Difference Between LEN and DATALENGTH Functions in SQL Server
LEN:- It shows actual Length of Declared Variable not as it’s Capacity.
Explanation:-
Char(50),Here we declare on Char variable with 50 character capacity .
But we assigned ‘Rahul’ only 5 character.
This Actual Length is called Len of a Variable.
DATALENGTH:- But DATALENGTH shows the capacity of a Variable.
Char(50) here 50 is the capacity of char Variable.
DECLARE @str CHAR(50)
SET @str='Rahul'
SELECT LEN(@str) AS LenCount
SELECT DATALENGTH(@str) AS DataLengthCount
No comments:
Post a Comment