Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 CONVERT to varbinary truncation

Author  Topic 

psk1
Starting Member

1 Post

Posted - 2008-10-15 : 19:18:48
Consider the following:

quote:

SELECT len(CONVERT(varbinary, '1234567890'));



Yields '10'. The following statement:

quote:

SELECT len(CONVERT(varbinary, '1234567890'));



Yields '20'. Now this statement:

quote:

SELECT len(CONVERT(varbinary, '1234567890123456789012345678901234567890'));



Yields '30'. Why isn't it 40 (the length of the string passed)?

PeterNeo
Constraint Violating Yak Guru

357 Posts

Posted - 2008-10-16 : 00:19:08
varchar, varbinary data types takes 30 as their default length unless we specify,
check this also
SELECT len(CONVERT(varchar, '1234567890123456789012345678901234567890'));

try this to get the correct length
SELECT len(CONVERT(VARBINARY(MAX), '1234567890123456789012345678901234567890'));
Go to Top of Page
   

- Advertisement -