Hi all,
I have a question about case statements and nulls in a where clause.
I want to do the following:
Declare @someVar int = null
select column1 as a from
TestTable t
where column1 = case when @someVar is not null then @someVar else column1 end
Here is the problem:
Let's say @someVar is null. Let's also say that column1 from TestTable t has NULL column values. Then, my condition t = t in the case statement will always evaluate to false.
I basically just want to be able to conditionally filter the column based on the value of @someVar if it's provided. Any help?