Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 EMERGENCY! How to get length of a Text field

Author  Topic 

theboyholty
Posting Yak Master

226 Posts

Posted - 2011-05-26 : 07:09:11
I can't use LEN() because its a text field and if I convert it to VARCHAR, it truncates it to 255 characters.

I need this quick so any advice would be muchly appreciated.

---------------------------------------------------------------------------------
http://www.mannyroadend.co.uk The official unofficial website of Bury Football Club

theboyholty
Posting Yak Master

226 Posts

Posted - 2011-05-26 : 07:14:22
All sorted. Didn't realise I could cast it to VARCHAR(8000), thought it only went up to 255.

---------------------------------------------------------------------------------
http://www.mannyroadend.co.uk The official unofficial website of Bury Football Club
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-05-26 : 07:14:52
cast it as varchar(max).

When you convert to varchar, you can go up to 8000. That you are seeing only 255 is probably a setting in SQL Server Management Studio - you can change it in Tools Options -> Query Results.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-05-26 : 07:27:23
Please see here also - regarding the difference between LEN() and DATALENGTH().
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=55456


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -