Click to Rate and Give Feedback
MSDN
MSDN Library
SQL Server
SQL Server 2005
 DATALENGTH (Transact-SQL)
Community Content
In this section
Statistics Annotations (0)
Collapse All/Expand All Collapse All
SQL Server 2005 Books Online (November 2008)
DATALENGTH (Transact-SQL)

Returns the number of bytes used to represent any expression.

Topic link icon Transact-SQL Syntax Conventions

DATALENGTH ( expression ) 
expression

Is an expression of any data type.

bigint if expression is of the varchar(max), nvarchar(max) or varbinary(max) data types; otherwise int.

DATALENGTH is especially useful with varchar, varbinary, text, image, nvarchar, and ntext data types because these data types can store variable-length data.

The DATALENGTH of NULL is NULL.

ms173486.note(en-US,SQL.90).gifNote:
Compatibility levels can affect return values. For more information about compatibility levels, see sp_dbcmptlevel (Transact-SQL)

The following example finds the length of the Name column in the Product table.

USE AdventureWorks;
GO
SELECT length = DATALENGTH(Name), Name
FROM Production.Product
ORDER BY Name;
GO
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2010 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker