title: "DATALENGTH (Transact-SQL) | Microsoft Docs" ms.custom: "" ms.date: "07/29/2017" ms.prod: "sql" ms.prod_service: "database-engine, sql-database, sql-data-warehouse, pdw" ms.service: "" ms.component: "t-sql|functions" ms.reviewer: "" ms.suite: "sql" ms.technology:
- "database-engine" ms.tgt_pltfrm: "" ms.topic: "language-reference" f1_keywords:
- "DATALENGTH_TSQL"
- "DATALENGTH" dev_langs:
- "TSQL" helpviewer_keywords:
- "number of bytes representing expression"
- "data types [SQL Server], length"
- "DATALENGTH function"
- "expressions [SQL Server], length"
- "lengths [SQL Server], data" ms.assetid: 00f377f1-cc3e-4eac-be47-b3e3f80267c9 caps.latest.revision: 31 author: "edmacauley" ms.author: "edmaca" manager: "craigg" ms.workload: "Active" monikerRange: ">= aps-pdw-2016 || = azuresqldb-current || = azure-sqldw-latest || >= sql-server-2016 || = sqlallproducts-allversions"
[!INCLUDEtsql-appliesto-ss2008-all-md]
Returns the number of bytes used to represent any expression.
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.
Note
Compatibility levels can affect return values. For more information about compatibility levels, see ALTER DATABASE Compatibility Level (Transact-SQL).
The following example finds the length of the Name column in the Product table.
-- Uses AdventureWorks
SELECT length = DATALENGTH(EnglishProductName), EnglishProductName
FROM dbo.DimProduct
ORDER BY EnglishProductName;
GO LEN (Transact-SQL)
CAST and CONVERT (Transact-SQL)
Data Types (Transact-SQL)
System Functions (Transact-SQL)