DECLARE @Test_len VARCHAR(20)
DECLARE @Test_Dlen NVARCHAR(20)
SET @Test_len = 'Find Length'
SET @Test_Dlen = 'Find Length'
SELECT
LEN(@Test_len) AS DATA1_LEN,
DATALENGTH(@Test_len) AS DATA1_DLEN,
LEN(@Test_Dlen) AS DATA2_LEN,
DATALENGTH(@Test_Dlen) AS DATA2_DLEN
Above example, two variable have declared in two different datatypes.
=> Where as Len will count only the length of strings in the column and
=> Datalength will count the length of string as per datatype.
In short, LEN is used to return number of character In string and
In DataLength is used for number of bytes.
DECLARE @Test_Dlen NVARCHAR(20)
SET @Test_len = 'Find Length'
SET @Test_Dlen = 'Find Length'
SELECT
LEN(@Test_len) AS DATA1_LEN,
DATALENGTH(@Test_len) AS DATA1_DLEN,
LEN(@Test_Dlen) AS DATA2_LEN,
DATALENGTH(@Test_Dlen) AS DATA2_DLEN
Above example, two variable have declared in two different datatypes.
=> Where as Len will count only the length of strings in the column and
=> Datalength will count the length of string as per datatype.
In short, LEN is used to return number of character In string and
In DataLength is used for number of bytes.