SQL Server 2005 Weird varchar Behavior

Posted by Tom Tresansky on Stack Overflow See other posts from Stack Overflow or by Tom Tresansky
Published on 2010-04-20T14:40:28Z Indexed on 2010/04/20 14:43 UTC
Read the original article Hit count: 214

Filed under:
|
|

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

  1. The assignment SET @Test1 = 'dog'; to fail because there isn't enough room in @Test1
  2. Or the SELECT to return 'dog' in the Result1 column.

What is up with @Test1? Could someone please explain this behavior?

© Stack Overflow or respective owner

Related posts about sql-server

Related posts about sql-server-2005