Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

DATALENGTH

Example

Retrieve the byte length of an expression.

SELECT DATALENGTH(‘W3Schools.com’);

Definition and Usage

The DATALENGTH() function calculates the number of bytes used to store an expression, including leading and trailing spaces.

Tip: Consider using the LEN() function to count the number of characters in a string, excluding spaces.

Syntax

DATALENGTH(expression)

Parameter Values

Parameter

Description

separator

Mandatory. Specifies the data type for which to retrieve the length. If the expression is NULL, the function returns NULL.

Technical Details

Works in:

SQL Server (from 2008 onward), Azure SQL Database, Azure SQL Data Warehouse, and Parallel Data Warehouse

More Examples

Example

Retrieve the byte length of an expression, accounting for both leading and trailing spaces.

SELECT DATALENGTH(‘   W3Schools.com   ‘);

Example

Retrieve the byte length of a given expression.

SELECT DATALENGTH(‘2017-08’);