Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Difference Between LEN and DATALENGTH Functions in SQL Server

Sep 19, 2012
Introduction:

In this article I will explain differences between Len() and DataLength() functions in sql server.

Description:

In previous post I explained differences between char, varchar and nvarchar, difference between tinyint,smallint,int,bigint and many articles relating to SQL Server. Now I will explain differences between Len() and DataLength() functions in SQL Server.

Len() function

This Len() function will return number of characters in the string expression excluding the trailing blanks. This mean it will right trim the blank values and give you the count of characters.

DataLength() function

This DataLength() function will return number of bytes to represent any expression. This mean it will give you a storage space required for the characters.

Check below examples for Len() and DataLength() functions

Example1:

In this example I am taking string value without spaces


DECLARE @str VARCHAR(50)
SET @str='Suresh'
SELECT LEN(@str) AS LenCount
SELECT DATALENGTH(@str) AS DataLengthCount
OutPut

Example2:

In this example I am taking string value with spaces


DECLARE @str VARCHAR(50)
SET @str='Suresh   '
SELECT LEN(@str) AS LenCount
SELECT DATALENGTH(@str) AS DataLengthCount
OutPut


If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

3 comments :

Anonymous said...

Nice example...

Anonymous said...

Very informative.

Anonymous said...

Where is the output?

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.