I want to write a query in a stored proc with many filters but I want to avoid dynamic SQL.
Say my parameters are nullable (@filter1, @filter2, @filter3...). One way I might solve this is:
SELECT col1, col2, col3
FROM table
WHERE col1 = ISNULL(@filter1, col1)
AND col2 = ISNULL(@filter2, col2)
AND col3 = ISNULL(@filter3, col3)
The result of this would filter by the appropriate filters if not null. The question is: 1) Is this good a practice? 2) Will the optimizer optimize the col1 = col1 out or will this affect query performance?