How can I return IS NOT NULL on from a SQL Server CASE statement?
I have tried something like this:
WHERE
a.BillToCustomerID IS NOT NULL
AND CASE @taxSchedRequiered
WHEN 1 THEN a.TaxScheduleID IS NOT NULL
END
but it is not working for me.
Update
I need to filter by a.TaxScheduleID IS NOT NULL, just in the specific case when the value of the variable @taxSchedRequiered (possible values are: null, 0, 1) is 1.
where 'TRUE' = case when @taxSchedRequired = 1 and a.TaxScheduleID is not null then 'TRUE' else 'FALSE' end and a.BillToCustomerID is not nullCASEin T-SQL is an expression (likea+b- not a statement) that can return one, atomic value (from several possible values) - but you cannot useCASEto conditionally/optionally add/run code snippets like you're trying to do.....