declare @a varchar(5)='56767'
select LEN(@a)
It will result into 56767.
DECLARE @a VARCHAR ='xyz'
SELECT
LEN(@a) AS 'Declared'
, LEN(CONVERT(VARCHAR,'xyz')) AS 'Converted'
, LEN(CAST('xyz' AS VARCHAR)) AS 'Cast'
When we use variable in Len method it will result us the length on basis of variable size. while in another statement LEN(CONVERT(VARCHAR,'xyz')) AS 'Converted' it is just convert the string 'xyz' into varchar, thus it result 3
select LEN(CONVERT(VARCHAR,'xyz')) AS 'Converted' -- Result 3
select LEN('xyx') -- Result 3
Same in case with CAST
Hope you get it now!! 🙂
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/