The simple question:
Is there an easy way to convert a Null to another value inline?
If I could use Nz (which is specific to Access only) it would look something like this:
SET @DebugMessage = @DebugMessage + CAST(Nz(@CurrentStatus,'Null') AS varchar(5))
So the string 'Null' is added to the message instead of getting an error on trying to convert a Null to varchar.
I appreciate anyone's help!
-E²
Non-obligatory reading to follow. A man's got to have the opportunity to complain, *somewhere*.
I just spent a few hours beating my brains out trying to understand the misbehavior of my stored procedure and finally realized the problem: Nulls.
It took me half the time to realize that gee, since Nulls propagate, if I concatenate a string to a Null I'll still have Null! Brilliant.
It took me the other half of the time to find out there is a debugger, get it going (sort of), receive the error message "[Microsoft][ODBC SQL Server Driver]Invalid character value for cast specification" but not be able to step through code or be told a line number, and finally nail this down to lines where I was doing "CAST(@MyValue AS varchar(6))" when @MyValue was Null.
It was so confusing because I never received an error message in the Results pane, the stored procedure just up and quit, leaving me to discover this only by inspecting results and finding them missing...
I just realized I could write my own function to do this. Hm.
Is there an easy way to convert a Null to another value inline?
If I could use Nz (which is specific to Access only) it would look something like this:
SET @DebugMessage = @DebugMessage + CAST(Nz(@CurrentStatus,'Null') AS varchar(5))
So the string 'Null' is added to the message instead of getting an error on trying to convert a Null to varchar.
I appreciate anyone's help!
-E²
Non-obligatory reading to follow. A man's got to have the opportunity to complain, *somewhere*.
I just spent a few hours beating my brains out trying to understand the misbehavior of my stored procedure and finally realized the problem: Nulls.
It took me half the time to realize that gee, since Nulls propagate, if I concatenate a string to a Null I'll still have Null! Brilliant.
It took me the other half of the time to find out there is a debugger, get it going (sort of), receive the error message "[Microsoft][ODBC SQL Server Driver]Invalid character value for cast specification" but not be able to step through code or be told a line number, and finally nail this down to lines where I was doing "CAST(@MyValue AS varchar(6))" when @MyValue was Null.
It was so confusing because I never received an error message in the Results pane, the stored procedure just up and quit, leaving me to discover this only by inspecting results and finding them missing...
I just realized I could write my own function to do this. Hm.