Friday, February 12, 2016

len vs datalength - sql

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.

No comments:

Post a Comment

Opps Part 1 : Abstraction

  Abstraction in C# is a fundamental concept of object-oriented programming (OOP) that allows developers t...