I have a stored procedure that fetches info from a table based on 4 parameters.
I want to get values based on the parameters, but if a parameter is NULL then that pa
This will work and easier to understand, at least for me.
The IIF statement is only available in SQL Server 2012 and up, you can replace it with a case statement.
SELECT Id, col1, col2, ...
FROM myTable
WHERE condition1 = IIF(col1 IS NULL, col1, @Param1)
AND condition2 = IIF(col2 IS NULL, col2, @Param2)...