I have dynamic sql in a sproc that takes a few optional parameters.
One of the parameters is an NVARCHAR and it's default value is NULL.
In the dynamic query string I check for null so that if the parameter
is not passed, I can get all records. Something like this:
Alter Procedure MySproc(MyChar NVARCHAR(50)=NULL, other
DECLARE SQL NVARCHAR(3000)
SQL='SELECT fields FROM tblBlah WHERE fldChar = ISNULL(' +
QUOTENAME(MyChar,'''') + ', fldChar)'
The problem is that when I don't pass in anything for the NVARCHAR
parameter, it surrounds the word NULL with quotes, which is not