I have a stored procedure where I am passing a value to be used in the select statement in the where clause.
If the value that I am passing is NULL, I do not want it to be part of that portion of the where clause where it is used. In the example below, variable2 is the variable I am passing to the stored procedure and using in the sql statement but if @variable2 is NULL, I do not want to use variable2= @val1 in the where clause. Example:
select Field1, Field2 from tbl1
where variable2= @val1
and ID = 'test'
Try: