DEV Community

Cover image for Calculating length of ntext data type with T-SQL
Ferhat Karataş
Ferhat Karataş

Posted on

3 2

Calculating length of ntext data type with T-SQL

We use the LEN() function when calculating the length of a String field. But when you use this function in fields with ntext datatype, you will get the following error.

Argument data type ntext is invalid for argument 1 of len function.
Enter fullscreen mode Exit fullscreen mode

In this case, another function you can use as an alternative is DATALENGTH()

But DATALENGTH returns us the number of bytes instead of the number of characters. Each character in the String is 2 bytes.

For example, if the result is 28, it means it's 14 characters.

select top 1 datalength(NameSurname), NameSurname from Customer order by CreateDate
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more