where子句中case语句的问题 [英] problems with case statement in where clause
问题描述
我想知道是否有人能告诉我这里的代码有什么问题:
SELECT COUNT(*)
FROM CALL
WHERE CALL.DESCRIPTION =
CASE
WHEN @ Param1 =''In''THEN''in''
WHEN @Param1 =''Out''THEN''Out''
END
我收到错误,参数是正确的。
如果有任何混淆,我会接受1个参数,即要么是'In''还是''Out''。根据参数,我想将Call.Description设置为In或Out。
提前感谢!
I was wondering if someone would be able to tell me what is wrong with my code here:
SELECT COUNT(*)
FROM CALL
WHERE CALL.DESCRIPTION =
CASE
WHEN @Param1 = ''In'' THEN ''In''
WHEN @Param1 = ''Out'' THEN ''Out''
END
I am getting an error that parameter is correct.
And just in case there is any confusion, I am taking in 1 parameter that is either going to be ''In'' or ''Out''. Depending on the param, I want to set Call.Description to either ''In'' or ''Out''.
Thanks in advance!
推荐答案
我想知道是否有人能告诉我这里的代码有什么问题:
SELECT COUNT(*)
FROM CALL
WHERE CALL.DESCRIPTION =
CASE
WHEN @ Param1 ='''''''''''''
WHEN @ Param1 =''Out''THEN''Out''
END
我收到一个错误,参数是正确的。
为了防止出现任何混淆,我接受1个参数,要么是' '在''或''出''。根据参数,我想将Call.Description设置为In或Out。
提前致谢!
I was wondering if someone would be able to tell me what is wrong with my code here:
SELECT COUNT(*)
FROM CALL
WHERE CALL.DESCRIPTION =
CASE
WHEN @Param1 = ''In'' THEN ''In''
WHEN @Param1 = ''Out'' THEN ''Out''
END
I am getting an error that parameter is correct.
And just in case there is any confusion, I am taking in 1 parameter that is either going to be ''In'' or ''Out''. Depending on the param, I want to set Call.Description to either ''In'' or ''Out''.
Thanks in advance!
你得到了什么错误?
你实际上可以这样做:
What error are you getting?
You can actually just do this:
你得到什么错误?
你实际上可以这样做:
What error are you getting?
You can actually just do this:
如果我理解正确的话:
如果@param =''在''那么你想要所有行都有CALL.DESCRIPTION = In''。
如果@param =''Out''那么你想要所有的行都有CALL.DESCRIPTION = Out''。
if @param =''Any''那么你想要所有的行,CALL.DESCRIPTION =''In''或CALL.DESCRIPTION =''Out''
>
如果我的假设是错误的,请不要阅读以下内容,否则请尝试以下操作:
So if I understand it right:
if @param = ''In'' then you want all rows with CALL.DESCRIPTION = In''.
if @param = ''Out'' then you want all rows with CALL.DESCRIPTION = Out''.
if @param = ''Any'' then you want all rows, both CALL.DESCRIPTION = ''In'' or CALL.DESCRIPTION = ''Out''
If my assumption is wrong, don''t read the following, otherwise try the following:
这篇关于where子句中case语句的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!