[英]Unable to pass variable in Informix
I was able to figure out how to get connected to Avaya CMS through Informix using SQL.我能够弄清楚如何使用 SQL 通过 Informix 连接到 Avaya CMS。 The below query works but when I try to replace the ''1/01/19'' with a variable, I get the following error: "EIX000: (-1205) Invalid month in date"
以下查询有效,但是当我尝试用变量替换“1/01/19”时,出现以下错误:“EIX000: (-1205) Invalid month in date”
Code that works有效的代码
select * from Openquery(CMS, 'select * FROM dagent WHERE ROW_DATE = ''1/01/19'' ');
Code that does not work不起作用的代码
DECLARE @startDate DATETIME
SET @startDate = '2021-01-21'
select * from Openquery(CMS, 'select * FROM dagent WHERE ROW_DATE = ''+@startDate+'' ');
Does anyone have an idea what the problem could be?有谁知道问题可能是什么?
The trouble is not enough single quotes.麻烦的是单引号不够。
You have:你有:
'select * FROM dagent WHERE ROW_DATE = ''+@startDate+'' '
^^ ^^
In each case where you have two adjacent single quotes, you need a third too.在每种情况下,如果您有两个相邻的单引号,您也需要第三个。 The two single quotes map to one single quote, so the quoted string contains
+@startDate+
, not the concatenation of your variable.两个单引号 map 到一个单引号,因此引用的字符串包含
+@startDate+
,而不是变量的串联。
You need:你需要:
'select * FROM dagent WHERE ROW_DATE = '''+@startDate+''' '
Now the first two single quotes in the triplet map to a single quote;现在将三元组 map 中的前两个单引号改为单引号; the third terminates the string, the
+@startDate+
becomes string concatenation, and then the next single quote starts a new string, the two single quotes map to one quote, and the space and single quote finish the string.第三个终止字符串,
+@startDate+
变成字符串连接,然后下一个单引号开始一个新的字符串,两个单引号 map 到一个引号,空格和单引号结束字符串。
How to debug?如何调试?
Assign the string you used to a variable and print it.将您使用的字符串分配给变量并打印它。
Assign the string I suggest to a variable and print it.将我建议的字符串分配给一个变量并打印它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.