Sunday, 27 August 2017

Difference Between LEN and DATALENGTH Functions in SQL Server

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

React Hooks - custom Hook

  v CustomHook Ø React allows us to create our own hook which is known as custom hook. Example – 1 localStorage Demo Step-1 Create ...