I am building some prepared statements that use parametrized values. As an example:
SELECT * FROM "Foo" WHERE "Bar"=@param
Sometimes @param
might be NULL
. In such cases, I want the query to return records where Bar
is NULL
, but the above query will not do that. I have learned that I can use the IS
operator for this. In other words:
SELECT * FROM "Foo" WHERE "Bar" IS @param
Aside from the differing treatment of NULL
, are there any other ways in which the above two statements will behave differently? What if @param
is not NULL
, but is instead, let's say, 5
? Is using the IS
operator in that case a safe (and sane) thing to do? Is there some other approach I should be taking?