Data length in ntext column?

How to find out the length and size of data in an ntext column in SQL? - This is longer than 8000 bytes, so I can not attribute it to varchar. Thank.

+41
sql-server
Oct 23 '08 at 15:05
source share
3 answers

Use DataLength ()

SELECT * FROM YourTable WHERE DataLength(NTextFieldName) > 0 
+64
Oct 23 '08 at 15:08
source share
— -

Key in the question: use DATALENGTH() . Note that this has a different behavior for LEN() :

 SELECT LEN(CAST('Hello ' AS NVARCHAR(MAX))), DATALENGTH(CAST('Hello ' AS NVARCHAR(MAX))), DATALENGTH(CAST('Hello ' AS NTEXT)) 

returns 5, 16, 16.

In other words, DATALENGTH() does not remove trailing spaces and returns the number of bytes, while LEN() trims trailing spaces and returns the number of characters.

+18
Oct 24 '08 at 8:27
source share
 Select Max(DataLength([NTextFieldName])) from YourTable 
0
Aug 15 '17 at 20:49 on
source share



All Articles