Reputation: 289
I have seen this link to find a solution to my problem:
However, in my case I need to evaluate that when a parameter has a certain value, it evaluates a field when it is null or not, for example:
WHERE (CASE @parameter WHEN 1 THEN a.fieldOne IS NULL ELSE a.fieldOne IS NOT NULL END)
But this doesn't work for me...
EDIT 1
For example when @parameter = 1
SELECT * FROM
FROM exampleTable as s
WHERE (s.fieldOne IS NULL)
And when @parameter = 0
SELECT * FROM
FROM exampleTable as s
WHERE (s.fieldOne IS NOT NULL)
Upvotes: 0
Views: 727
Reputation: 312259
You can't use a case
expression to return parts of a query like you tried, only values.
However, you could emulate his behavior with logical opertaors:
WHERE (@parameter = 1 AND a.fieldOne IS NULL) OR
(@parameter <> 1 AND a.fieldOne IS NOT NULL)
Upvotes: 3