Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.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
Sql server 2008 当charindex_Sql Server 2008_Syntax Error_Case - Fatal编程技术网

Sql server 2008 当charindex

Sql server 2008 当charindex,sql-server-2008,syntax-error,case,Sql Server 2008,Syntax Error,Case,我试图让这个case语句在SQLServer2008R2中工作。它一直说“>”符号在CHARINDEX部分的when语句中无效 select count(r.id) as request, case r.servicelayer when null then r.topic + '/IAL' when '' then r.topic + '/IAL' when CHARINDEX('/rssfeed1234/georss/SomMobile',

我试图让这个case语句在SQLServer2008R2中工作。它一直说“>”符号在
CHARINDEX
部分的when语句中无效

select 
   count(r.id) as request, 
   case r.servicelayer
      when null then r.topic + '/IAL'
      when '' then r.topic + '/IAL'
      when CHARINDEX('/rssfeed1234/georss/SomMobile', i.URI_STEM) ***>*** 0 then 'Som Mobile'
      else r.topic + '/' + r.servicelayer
    end as [layername]
from iis_metrics.tblReportData as r

好吧,您正在以无效的方式混合使用两种不同的
CASE

要么使用
大小写(某个列名)
,然后必须只使用对该列应用的某个条件。这在前两个子句中是可以的:
WHEN NULL
WHEN'
(这是一种使用
WHEN..is NULL
WHEN…='
的“速记”—但是如果你开始使用这个“速记”符号,你需要在所有
WHEN
子句中使用它)

但是在这种情况下,当您在第三个子句中尝试时,不能在
WHEN…
子句中突然有一个完整的表达式

这是版本:您也可以只使用
大小写
,然后在子句具有完整表达式时使用每个
-尝试以下操作:

CASE 
  WHEN r.servicelayer IS NULL THEN r.topic + '/IAL'
  WHEN r.servicelayer = '' THEN r.topic + '/IAL'
  WHEN CHARINDEX('/rssfeed1234/georss/SomMobile', i.URI_STEM) > 0 THEN 'Som Mobile'
  ELSE r.topic + '/' + r.servicelayer
END AS [layername]
现在应该可以使用了-当
子句包含完整表达式时,每个
,因此该
CASE
语句是有效的