ich so etwas tun, was gut funktioniert:warum SQL-Case-Fall geben Fehler
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,',','))
Aber wenn ich Fall verwenden, um eine Situation zu behandeln, in denen Benutzer dynamisch eintreten ‚‘ anstelle von ‚1,2,3, ". Dann gibt es Fehler in meinem Fall Zustand
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
Fehler sind:
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'.
A 'CASE' * Ausdruck * hat zurückzukehren ein Skalarwert (pro Zeile) eines SQL-Datentyps Es kann das Ergebnis der Auswertung eines Prädikats nicht zurückgeben, da dies ein boolescher Wert wäre - und SQL Server hat keinen booleschen Datentyp. –