Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/78.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.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 包含CharIndex的Case语句有问题_Sql_Sql Server - Fatal编程技术网

Sql 包含CharIndex的Case语句有问题

Sql 包含CharIndex的Case语句有问题,sql,sql-server,Sql,Sql Server,我不明白为什么这上面写着“附近的synax>不正确” case changeuserid when charindex('toolbar',lower(changeuserid) > 0 then 'TOOLBAR' when charindex('mflynn',lower(changeuserid) > 0 then 'MFLYNN' else (select username from CLAIMSAUDIT_USERS where MC400ID_PH

我不明白为什么这上面写着“附近的synax>不正确”

    case changeuserid
    when charindex('toolbar',lower(changeuserid) > 0 then 'TOOLBAR'
    when charindex('mflynn',lower(changeuserid) > 0 then 'MFLYNN'
else (select username from CLAIMSAUDIT_USERS where MC400ID_PHP=changeuserid)    
end AS 'dbusername',

您可以使用以下格式的
大小写
,而且由于
之前缺少
括号,因此存在语法错误

case 
    when charindex('toolbar',lower(changeuserid)) > 0 then 'TOOLBAR'
    when charindex('mflynn',lower(changeuserid) ) > 0 then 'MFLYNN'
    else (select username from CLAIMSAUDIT_USERS where MC400ID_PHP=changeuserid)    
end AS 'dbusername'

您缺少
charindex()
上的关闭参数。此外,您的
大小写
语法不正确。您有一个额外的
changeuserid

(case when charindex('toolbar', lower(changeuserid)) > 0 then 'TOOLBAR'
      when charindex('mflynn', lower(changeuserid)) > 0 then 'MFLYNN'
      else (select username from CLAIMSAUDIT_USERS where MC400ID_PHP = changeuserid)    
 end) AS 'dbusername',

非常感谢。我知道这是一个愚蠢的问题——但我对t-sql不是很有经验,有时是一些小事情让我绊倒。我现在看到了所有这些错误,以及我试图使用错误版本的Case(里面有完整的表达式)的事实。再次感谢你。