I am selecting records from has a column called [tagged], and it's defaulted to Zero.
My problem is when the @tagged
variable is NULL
, then I want to select both 0,1 values. This makes me think I should be doing an IF/ELSE
, but my attempts are failing.
--- simple example:
declare @tagged int = NULL
SELECT *
FROM [TableName]
WHERE datecreated > '2016-01-01'
AND tagged = @tagged
Many DBAs are recommending the CASE clause. But I need help knowing where to add it.
Do I add it inside the Query?
My feeble attempt was this:
SELECT *
FROM [TableName]
WHERE datecreated > '2016-01-01'
AND (
CASE @tagged
WHEN 0 THEN (tagged = 0)
WHEN 1 THEN (tagged = 1)
ELSE (tagged IN(0,1)
END
)