Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有聚合和类似条款的案例陈述-MSSQL 2012_Sql_Sql Server_Tsql - Fatal编程技术网

带有聚合和类似条款的案例陈述-MSSQL 2012

带有聚合和类似条款的案例陈述-MSSQL 2012,sql,sql-server,tsql,Sql,Sql Server,Tsql,我真的在为MSSQL 2012中的案例陈述而挣扎。我四处寻找其他答案,但尽管我得到了一些帮助,但似乎没有人能解决这个问题 case firstname when len(ltrim(rtrim(firstname))) > 11 then 'blah' else 'blahblah' end as test 我在“>”字符上遇到语法错误 原来这是 case firstname when ltrim(rtrim(firstname)) like '% %' then

我真的在为MSSQL 2012中的案例陈述而挣扎。我四处寻找其他答案,但尽管我得到了一些帮助,但似乎没有人能解决这个问题

case firstname
    when len(ltrim(rtrim(firstname))) > 11 then 'blah'
    else 'blahblah'
end as test
我在“>”字符上遇到语法错误

原来这是

case firstname
    when ltrim(rtrim(firstname)) like '% %' then 'blah'
    else 'blahblah'
end as test
但是我认为like关键字可能有一些敏感度,所以我把它改为“>”,但我得到了同样的结果

可能是个愚蠢的问题,但我已经绞尽脑汁几个小时了,如果能有一些见解,我将不胜感激。

试试这个版本:

(case when len(ltrim(rtrim(firstname))) > 11 then 'blah'
      else 'blahblah'
 end) as test
case
语句有两个版本。带有变量的用于常量表达式:

(case firstname
      when 'Arnold' then . . .
      when 'Betty' then . . .
 end)
第二个版本(实际上是我唯一使用的版本)对每个部分都有一个条件:

(case when firstname = 'Arnold' then . . .
将其更改为

case 
    when len(ltrim(rtrim(firstname))) > 11 then 'blah'
    else 'blahblah'
end as test

你把这两种形式的爱混在一起了

一个简单的case表达式检查每个
WHEN
子句是否与
case
之后和第一个
WHEN
之前的表达式相等

搜索的case表达式在每个
WHEN
子句中检查单独的任意谓词,并且在
case
和第一个
WHEN
之间没有表达式

尝试:

case
    when len(ltrim(rtrim(firstname))) > 11 then 'blah'
    else 'blahblah'
end as test