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

Complete Authentication System in ASP.NET Core using JWT

JWT (JSON Web Token) authentication is widely used for securing APIs in modern applications. In this article, we will build a complete authe...