SQL Where question
- by needshelp
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 from
TestTable t
where t = case when @someVar is not null then @someVar else t 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?