SQL Server 2005 Weird varchar Behavior
- by Tom Tresansky
This SQL Server 2005 T-SQL code:
DECLARE @Test1 varchar;
SET @Test1 = 'dog';
DECLARE @Test2 varchar(10);
SET @Test2 = 'cat';
SELECT @Test1 AS Result1, @Test2 AS Result2;
produces:
Result1 = d
Result2 = cat
I would expect either
The assignment SET @Test1 =
'dog'; to fail because there isn't
enough room in @Test1
Or the SELECT to return 'dog' in the Result1 column.
What is up with @Test1? Could someone please explain this behavior?