I am using SWITCH Statement in SP under Where Clause.Query Seems to be fine but i am unable to understand why it is giving me the error. Query is:
Select * from Customer
WHERE (I.IsClose=@ISClose OR @ISClose is NULL)
AND
(C.FirstName like '%'+@ClientName+'%' or @ClientName is NULL )
AND
CASE @abc
WHEN 2 THEN I.RecurringCharge=@Total or @Total is NULL
WHEN 3 THEN I.RecurringCharge like
'%'+cast(@Total as varchar(50))+'%'
or @Total is NULL
END
The code is incomplete but sufficient to understand the problem.I am getting Below Error Message when trying to compile it.
Incorrect syntax near '='.
The Error is on following line.
WHEN 2 THEN I.RecurringCharge=@Total or @Total is NULL
Please help me experts.
Thanks in advance.
CASEstatement can only return (atomic) values (like 1,Hello) - not entire code blocks or expressions...WHEREclause, you're trying to assign variables and stuff.....