I have a variable age to be used on my query like below:
Declare @age as int 11
Select * from people p where p.age = @age
but I want to show all the people between 10 and 13 when I put 0 on @age, so I’m trying to do something like this:
Select *
from people p
where p.age in( case
when @age = 0
then 10, 11, 12, 13
else @age
end
)
Can someone give me a light?
You do not need a
CASEstatement, you can just switch yourWHEREclause around a bit. This should return the same results: