Reputation: 2108
In some stored procedures I see the following statement in where
clause:
...
where
(@val1 is null or val = @val)
What does it mean?
Upvotes: 0
Views: 30
Reputation: 34543
I have used this before in a stored procedure when passing a variable that is used to filter the result set. The null
value signifies that the parameter should not be used as a filter.
@val1
is null, then the expression is true and the results are not filtered.@val1
is not null, then the results will be filtered and the val
column must match the parameter.Upvotes: 3