Jeremy Kern Jeremy Kern - 3 months ago 5x
SQL Question

Case expression with a parameter fails

I want to only use the where condition if Make is not equal to '0'. This is what I have tried. This is a snippet from the stored proc. Query works only when Make is not 0. When it is '0' it fails.

This is not a null check. @Make is a varchar. How it is implemented is either it will be '0' or it will be a string e.g 'mazda'.

select *
from In_Inventory
and Make = case
when @Make != '0'
Then @Make


Try something like this

FROM In_Inventory
WHERE @Make = 0
OR Make = @Make