SQL Server 2000“关键字“CASE”附近的语法不正确”
当尝试执行以下存储过程时,将返回错误:
EXECUTE p_someProc
--list of vars
CASE WHEN @var1=1 AND @var2=1 THEN 3
WHEN @var2=1 THEN 2
WHEN @var1=1 THEN 1 END,
--more vars
还包括其他 CASE 函数,但只出现一个指向第一个 CASE 的错误。
当在 PRINT 函数中运行相同的表达式时,将返回预期结果。
declare @var1 bit set @var1 = 1
declare @var2 bit set @var2 = 1
print(CASE WHEN @var1=1 AND @var2=1 THEN 3
WHEN @var1=1 THEN 2
WHEN @var2=1 THEN 1 END)
输出是“3”
我认为我以某种方式滥用了 CASE 函数。有人能想到解决方法或修复它的方法吗?
提前致谢。
——斯坦
The error is return when the following stored proc is attempted to be executed:
EXECUTE p_someProc
--list of vars
CASE WHEN @var1=1 AND @var2=1 THEN 3
WHEN @var2=1 THEN 2
WHEN @var1=1 THEN 1 END,
--more vars
There are other CASE functions included, though only a single error is spewed up which points to the first CASE.
When the identical expression is run within a PRINT function, an expected result is returned.
declare @var1 bit set @var1 = 1
declare @var2 bit set @var2 = 1
print(CASE WHEN @var1=1 AND @var2=1 THEN 3
WHEN @var1=1 THEN 2
WHEN @var2=1 THEN 1 END)
The output is '3'
I assume that I'm misusing the CASE function somehow. Could anyone think of a workaround or a way to fix it?
Thanks in advance.
--Stan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 JeremyMcGee 上面提到的,您需要执行分配而不是尝试将案例传递给执行人员,请尝试更像以下的操作
As JeremyMcGee alludes to above you need to perform an assignment rather than trying to pass the case to the exec, try something more like the following
如果没有更多代码,很难说清楚。检查 @var1 和 @var2 是否已声明?
确保您也将 CASE 的结果分配给某些东西!
Hard to tell without more code. Check that @var1 and @var2 have been declared, perhaps?
Make sure you're assigning the result of the CASE to something, too!