Home All Groups Group Topic Archive Search About

finding length of text field

Author
6 Jan 2006 10:42 PM
HP
I need to find the length of a text field.The len function doesn't work with
text fields.
Is there an alternative?
Thanks!

Author
6 Jan 2006 10:46 PM
Jens
Look in the BOL for DATALENGTH.

HTH, Jens Suessmeyer.
Author
6 Jan 2006 10:48 PM
Jens
Look in the BOL for DATALENGTH

HTH, jens Suessmeyer.
Author
6 Jan 2006 10:50 PM
Trey Walpole
DATALENGTH()

HP wrote:
Show quote
> I need to find the length of a text field.The len function doesn't work with
> text fields.
> Is there an alternative?
> Thanks!
Author
6 Jan 2006 11:44 PM
Erland Sommarskog
HP (H*@discussions.microsoft.com) writes:
> I need to find the length of a text field.The len function doesn't work
> with text fields.

As Jens and Trey said there is datalength().

In case you are using ntext, beware that datalength() returns the length
in bytes, and includes trailing blanks. For instance:

    SELECT len(N'August   '), datalength(N'August   ')

Returns (6, 18).


--
Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

AddThis Social Bookmark Button