gpt4 book ai didi

mysql - "You must provide a value expression on the right-hand side of the ' % ' operator."查询语句错误

转载 作者:行者123 更新时间:2023-11-29 23:09:02 25 4
gpt4 key购买 nike

我的 Powershell 脚本包含查询 -

# This code defines the search string in the database table
$SQLQuery = "SELECT bug_id,
bug_status,
resolution,
short_desc,
DATE_FORMAT(deadline, "%m/%d/%Y")
FROM bugs
WHERE ( bug_status IN ( 'RESOLVED', 'VERIFIED', 'INTEST' )
AND deadline BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 30 DAY)
)
OR ( bug_status IN ( 'RESOLVED', 'VERIFIED', 'INTEST' )
AND deadline BETWEEN DATE_SUB(CURDATE(), INTERVAL 30 DAY) AND
CURDATE() )
ORDER BY deadline ASC

"

运行脚本时,它在日期格式部分失败并出现以下错误 -

You must provide a value expression on the right-hand side of the '%' operator.
At line:5 char:32
+ DATE_FORMAT(deadline, "% <<<< m/%d/%Y")
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ExpectedValueExpression

关于如何转义这些字符有什么建议,但同时它应该影响将在 MySql 数据库上触发的实际查询?

最佳答案

您在双引号字符串中使用了双引号。未转义的嵌套双引号会过早终止字符串,因此 PowerShell 将 % 解释为运算符,而不是字符串的一部分。

尝试用单引号替换嵌套的双引号,并使您的字符串成为正确的多行字符串:

$SQLQuery = @"
SELECT bug_id,
...
DATE_FORMAT(deadline, '%m/%d/%Y')
...
"@

关于mysql - "You must provide a value expression on the right-hand side of the ' % ' operator."查询语句错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28160062/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com