在 T-SQL 的 where 子句中使用 CASE?
我尝试使用 case 来改变在 where 子句中检查的值,但出现错误:
关键字 'CASE'
SQL Server 2005附近的语法不正确
select *
from table
where ((CASE when adsl_order_id like '95037%'
then select '000000'+substring(adsl_order_id,6,6)
ELSE select adsl_order_id
END)
not in (select mwebID from tmp_csv_dawis_bruger0105)
Im trying to use case to vary the value im checking in a where clause but I'm getting the error:
incorrect syntax near the keyword 'CASE'
SQL Server 2005
select *
from table
where ((CASE when adsl_order_id like '95037%'
then select '000000'+substring(adsl_order_id,6,6)
ELSE select adsl_order_id
END)
not in (select mwebID from tmp_csv_dawis_bruger0105)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
以下是将 case 语句包含在 Where 子句中的一种方法:
Here is one way to include a case statement in a Where clause:
你可以尝试
You could try
相关子查询是一种可能性:
A correlated subquery is one possibility:
我来到这个问题寻找答案,思考 WHERE CASE ... 将是解决方案。我无法调整我的问题的答案,但这种使用可能为空、部分或特定的参数的技术是有效的:
HTH
I came to this question looking for an answer thinking WHERE CASE ... would be the solution. I could not adapt the answers to my problem, but this technique to use a parameter that could be null, partial, or specific, works:
HTH
CASE 表达式前的左括号过多。
You have one too many opening parentheses before the CASE expression.
将其放在 SELECT 子句中...
此外,您不需要“SELECT”CASE 的结果。
Put it in the SELECT clause...
Also, you don't need to "SELECT" the result of the CASE.