Returns the number of bytes occupied by any expression.
Syntax
DATALENGTH (expression)
Parameters
Expression
Any type of expression.
Return type
Int
Note
DATALENGTH is particularly useful for varchar, varbinary, text, image, nvarchar, and ntext data types because these data types can be stored
Variable length data.
The result of null datalength is NULL.
The compatibility level may affect the return value. For more information about the compatibility level, see sp_dbcmptlevel.
Example
This example shows the length of the pub_name column in the publishers table.
USE pubs
GO
SELECT length = DATALENGTH (pub_name), pub_name
FROM publishers
Order by pub_name
GO
The following is the result set:
Length pub_name
---------------------------------------------------
20 Algodata Infosystems
16 Binnet & Hardley
21 Five Lakes Publishing
5 GGG & G
18 Lucerne Publishing
14 New Moon Books
17 Ramona Publishers
14 Scootney Books
(8 row (s) affected)
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service