I am trying to write a SQL Select statement to return records based on user input through an interface. I want to write a Select statement as follows:
SELECT somefields
FROM sometable
WHERE CASE variable
WHEN 'blank' THEN field IS NULL
ELSE field = field
END
Basically, I either want the filter column to find NULL values or ignore the filter, and return all the values depending on the value of the variable. I know that the results of the CASE statement are not executed, but how can I do this?
source
share