我做这样的事情的正常工作:为什么SQL情况下条件给出错误
select nameOfCols
from
FACost
inner join FAT as D on d.nid=a.atypeid
and
d.nid in (select item from SplitString('1,2,3,',','))
但是当我使用情况来处理的情况下用户可以动态地“而不是“1,2,3输入”, ”。然后提示错误在我的情况条件
declare @selectedAssetTypeID varchar(50)='1,2,3,'
select nameOfCols
from
FACost
inner join FAT as D on d.nid=a.atypeid
and
case when @selectedAssetTypeID<>'' then d.nid in (select item from SplitString(@selectedAssetTypeID,',')) else d.nid=1 end //error causing lines
错误是:
Msg 156, Level 15, State 1, Line 33
Incorrect syntax near the keyword 'in'.
Msg 156, Level 15, State 1, Line 33
Incorrect syntax near the keyword 'else'.
一个'CASE' *表达*必须返回SQL数据类型的标量值(每行)。它不能返回评估谓词的结果,因为这将是一个布尔值 - 而SQL Server没有布尔数据类型。 –