Logo 
Search:

SQL Server Articles

Submit Article
Home » Articles » SQL Server » System FunctionsRSS Feeds

DATALENGTH Function

Posted By: Sarita Patel     Category: SQL Server     Views: 4394

This article explains about DATALENGTH function in sql server with examples.

DATALENGTH function returns number of bytes used to represent specified expression. 

It is a deterministic i.e It returns same value every time it is called with a specific set of values.


Syntax of DATALENGTH Function :

DATALENGTH ( expression )

expression is any valid sql server expression.

Return type of DATALENGTH function is an integer. 




Examples of DATALENGTH Function :

Example 1 : Use of DATALENGTH function in select clause 

SELECT DATALENGTH ( 'Syntax-Example' )

Output
14

Above example returns number of byte required for specified string.


Example 2 : Use of DATALENGTH function to display column value in select clause 

SELECT ProductName, DATALENGTH (ProductName) AS OccupiedLength
FROM    Products

Output
ProductName                                  OccupiedLength
Chai                                                  8
Chang                                              10
Aniseed Syrup                                   26
Chef Anton's Cajun Seasoning            56
Chef Anton's Gumbo Mix                    44
Grandma's Boysenberry Spread          56
Uncle Bob's Organic Dried Pears          62
Northwoods Cranberry Sauce              52


Above example returns number of bytes used to represent productname of products table.
  
Share: 

 
 

Didn't find what you were looking for? Find more on DATALENGTH Function Or get search suggestion and latest updates.

Sarita Patel
Sarita Patel author of DATALENGTH Function is from United States.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!