This is for those who use string concatenation to join character variables and hard coded strings to form some sort of new output.
I found this when trying to throw and error and using the variable to describe the nature of the error. It will affect your PRINT, SELECT, and SET statements too.
EG.
DECLARE @Output varchar(100), @SomeVar varchar(10)
SET @SomeVar = NULL
SET @Output = ‘This will be ‘ + @SomeVar
RAISERROR (@Output, 12, -1) — or what ever you want here
The problem with the above is that trying to concatenate a null with a string will make the entire string null. So throw in an ISNULL and then we’re all set.
SET @Output = ‘This will be ‘ + ISNULL(@SomeVar,’NULL’)
RAISERROR (@Output, 12, -1) — or what ever you want here
