During experiments with MSSQL, I came across some kind of behavior that I can not explain.
I watched what happens with a NULL value when it is added to varchar, and when I make the following request:
SELECT
ISNULL(NULL + ' ', 'test')
I get the result of 'te'. Similarly, if I change the word test for any other word, I get only the first two letters. If I increase the number of spaces in + '', 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, for example.
DECLARE @testnull AS varchar(32)
SET @testnull = NULL
SELECT
ISNULL(@testnull + ' ', 'test')
then I get the result of 'test' (as expected).
source
share