gene
gene

Reputation: 2108

how to understand the statement in SQL

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

Answers (1)

David
David

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.

  • If @val1 is null, then the expression is true and the results are not filtered.
  • If @val1 is not null, then the results will be filtered and the val column must match the parameter.

Upvotes: 3

Related Questions