SQL Server : conditional case in where clause
18,051
Something like this would work.
Declare @Result varchar(100)
Set @Result =''
Select *
From dbo.TABLE
Where [Result] Like Case
When @Result = '' Then @Result
Else @result + '%'
End
Author by
Matt
Updated on June 04, 2022Comments
-
Matt about 2 years
I would like to write the following as a
CASE
statement in myWHERE
clause, but I'm unsure how to write it.if @Result = '' then [Result] = @Result else [Result] like @Result + '%' endif
-
Matt about 11 yearsbang on mate. Many thanks, I'll accept your answer as soon as it lets me.