andrefadila andrefadila - 2 months ago 7
SQL Question

Query filter with CASE select NULL field [SQL Server]

How do I simplify this into one WHERE clause with CASE WHEN statement:

@param varchar(1) NULL

if @param = 'Y'
... WHERE field = @param
else if @param = 'N'
... WHERE field = @param OR field IS NULL


Thanks in advance

Answer

Like this : without CASE Expression

WHERE (@param='Y' AND field = @param ) OR  (@param='N' AND (field = @param OR field IS NULL))
Comments