gstackoverflow gstackoverflow - 5 months ago 22
SQL Question

sql print returns strange result

I have the following sql code:

DECLARE @result VARCHAR
SET @result = 'FN'
print(@result)


It returns
F
to console.
why?

Answer

If you define a VARCHAR, you have to specify it's length. If you don't it defaults to 1.

Use:

DECLARE @result VARCHAR(2)
SET @result = 'FN'
print(@result)