Retrieve the byte length of an expression.
SELECT DATALENGTH(‘W3Schools.com’); |
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.
DATALENGTH(expression) |
Parameter |
Description |
separator |
Mandatory. Specifies the data type for which to retrieve the length. If the expression is NULL, the function returns NULL. |
Works in: |
SQL Server (from 2008 onward), Azure SQL Database, Azure SQL Data Warehouse, and Parallel Data Warehouse |
Retrieve the byte length of an expression, accounting for both leading and trailing spaces.
SELECT DATALENGTH(‘ W3Schools.com ‘); |
Retrieve the byte length of a given expression.
SELECT DATALENGTH(‘2017-08’); |