I am building some prepared statements that use parametrized values. As an example:
SELECT * FROM \"Foo\" WHERE \"Bar\"=@param
Sometimes
You may be thinking about this incorrectly. If you're talking about SQL Server, for example (since that's what I have to hand), your second example will result in a syntax error. The value on the right-hand side of IS cannot be 5.
To explain, consider MSDN's explanation of these two operators in T-SQL (note that asking about "SQL" and about "SQL Server" are not necessarily the same).
Equals (=) operator
IS NULL operator
Notice something important, there. There is no such thing as the "IS" operator in T-SQL. There is specifically the
operator, which compares a single expression to NULL.
That's not the same thing as the =
operator, which compares two expressions to each other, and has certain behavior when one or both of the expressions happens to be NULL!