I am building some prepared statements that use parametrized values. As an example:
SELECT * FROM \"Foo\" WHERE \"Bar\"=@param
Sometimes
Edit: (Update from OP: This doesn't do what I If @param is 5, then I want to see only records where Bar is 5. I want to see records where Bar is NULL if, and only if, @param is NULL. I apologize if my question didn't make that clear.)
In that case, I think you should try something like this:
SELECT * FROM Foo WHERE Bar=@param OR (Bar IS NULL AND @param IS NULL)
Previous post:
Why not simply use OR ?
SELECT * FROM "Foo" WHERE "Bar"=@param OR "Bar" IS NULL
In SQL Server, you can use ISNULL:
SELECT * FROM "Foo" WHERE ISNULL("Bar",@param)=@param