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 2000 Forums
 Transact-SQL (2000)
 Select last 8000 characters in Text(16) field

Author  Topic 

thorv
Starting Member

7 Posts

Posted - 2006-11-13 : 16:35:45
If I use this select it will select the first 8000 characters:

select CAST(note AS varchar(8000)) from notes

But I need to select the last 8000 characters.

I have done this for many years ago I think, but I don't remember.

Someone that know this ?

Thor

X002548
Not Just a Number

15586 Posts

Posted - 2006-11-13 : 16:46:27
You need to look up TXTPTR and the like in BOL, then read the data out in chunks...

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-11-13 : 17:04:30
Can't you just use SUBSTRING and DATALENGTH?

SELECT SUBSTRING(MyText, DATALENGTH(MyText)-8000, 8000)

noting that if MyText is Nvarchar then DATALENGTH is returning Bytes not Characters

Kristen
Go to Top of Page

thorv
Starting Member

7 Posts

Posted - 2006-11-13 : 17:56:02
SELECT SUBSTRING(MyText, DATALENGTH(MyText)-8000, 8000) from mydata

gives me this error:
Expression result length exceeds the maximum. 8000 max, 16000 found

???? :-)
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-11-13 : 18:16:58
Could be that SUBSTRING on TEXT won't go past first 8,000 characters, but I read BoL carefully [kinda expecting that] but it makes no mention of any limitations.

If your MyText column is Nvarchar then you may need to count differently, because I think substring counts in Characters and DataLength in bytes.

Kristen
Go to Top of Page

thorv
Starting Member

7 Posts

Posted - 2006-12-14 : 18:47:31
The problem was NTEXT, changed it to TEXT, then your SQL sample works great :-)
Thanks !!

Thor
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2006-12-14 : 19:57:11
you can likely still use an ntext column if you pick the last 4000 chars instead.


http://www.elsasoft.org
Go to Top of Page
   

- Advertisement -