Earn income with your data and sql skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest self-service freelancing marketplace for people like you.

SQL DATALENGTH Function

The DATALENGTH function returns the number of bytes in a given expression.

If NULL is provided, this function returns NULL as well.

DATALENGTH returns the # of bytes, whereas LEN returns the # of characters.

Example

#

This example return the number of bytes of the input string.

SELECT DATALENGTH('Austin, Texas') AS 'Data Length'
Result:  1 record
Data Length
13

Syntax

Syntax of the DATALENGTH function.

DATALENGTH(expression)

expression -- a value of any data type, or column name.


More Examples

DATALENGTH with COLUMN

CUSTOMER
Id
FirstName
LastName
City
Country
Phone
Problem: List customers with the number of bytes in their first names.
SELECT FirstName, 
       DATALENGTH(FirstName) AS Bytes
  FROM Customer
Result:  91 records
FirstName Bytes
Paolo 10
Pedro 10
Marias 12
Kyle 8
Miguel 12

Note: FirstName is a NVARCHAR string, so each character is 2 bytes.


You may also like



Earn income with your data and sql skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest self-service freelancing marketplace for people like you.

Guides


vsn 3.1