Reminder To Self - Cannot Concatenate NULL in SQL Server 2000

microsoft, sql server

In SQL Server 2000, I'm not sure about 2005 yet, you can't concatenate on a NULL value.  The result will continue to be NULL.

By running this you get an output of NULL.

DECLARE @my_string VARCHAR(20)
SET @my_string = @my_string + 'something'
PRINT @my_string
 

You have to set the variable to something other than NULL before using concatenation.

DECLARE @my_string VARCHAR(20)
SET @my_string = ''
SET @my_string = @my_string + 'something'
PRINT @my_string

This had me hung up for almost an hour.


Search