我已经打破我的头在这个希望有可能SQL案例,并喜欢在where子句
declare @locationType varchar(50);
declare @SearchTerm NVARCHAR(100);
SELECT column1, column2
FROM whatever
WHERE
CASE @locationType
WHEN 'location' THEN account_location LIKE @SearchTerm
WHEN 'area' THEN Area LIKE @SearchTerm
WHEN 'division' THEN xxx_location_division LIKE @SearchTerm
END
我复制的代码形式另一个相关的帖子here。
我得到的错误:
Incorrect syntax near the keyword 'LIKE'.
所以'LIKE','WHERE'和'CASE'不一起?你的意思是以'/'开始并以'%'结尾? – Deeptechtons
==在sql中不起作用。 –
是的,我的错==。如果你在寻找“NEW”的地方,那么“@ SearchTerm”应该是“NEW%”。 –