I need to use if statement inside where clause in sql.
Select * from Customer
WHERE (I.IsClose=@ISClose OR @ISClose is NULL)
AND
(C.FirstName like '%'+@ClientName+'%' or @ClientName is NULL )
AND
if (@Value=2)
begin
(I.RecurringCharge=@Total or @Total is NULL )
end
else if(@Value=3)
begin
(I.RecurringCharge like '%'+cast(@Total as varchar(50))+'%' or @Total is NULL )
end
Note:This is not the complete code.Everything is defined in SP.I Just written the code that was needed to understand the issue.
Thanks in advance.
See Question&Answers more detail:os