Got to know that by default it takes the length as 1 if the size is not declared. Thank you....
However, I still did not get the difference between length of normal declaration and Cast/Convert... Please find below the queries....
1) SELECT
LEN('xyz') AS 'Declared'
, LEN(CONVERT(VARCHAR,'xyz')) AS 'Converted'
, LEN(CAST('xyz' AS VARCHAR)) AS 'Cast'
Ans : 3,3,3
2)
DECLARE @a VARCHAR ='xyz'
SELECT
LEN(@a) AS 'Declared'
, LEN(CONVERT(VARCHAR,@a)) AS 'Converted'
, LEN(CAST(@a AS VARCHAR)) AS 'Cast'
Ans : 1,1,1
I did not get default of 30 (which you mentioned in the answer in case of Cast/Convert) in what ever way I try... Can you please explain more on this?