Whilst experimenting with MSSQL I came across some behaviour I cannot explain.
I was looking at what happens to a NULL value when it is added to a varchar, and when I do the following query:
SELECT
   ISNULL(NULL + ' ', 'test')
I get the result 'te'. Similarly if I change the word test for any other word I only get the first two letters. If I increase the number of spaces in the + ' ' I get extra letters in my result (so NULL + '[two spaces]' gives me 'tes'). Any ideas what is going on?
If I declare a variable and set it to NULL e.g.
DECLARE @testnull AS varchar(32)
SET @testnull = NULL
SELECT
ISNULL(@testnull + ' ', 'test')
then I get the result 'test' (as I would expect).

