andrefadila andrefadila - 26 days ago 5x
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


Like this : without CASE Expression

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