Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alternative to LEFT() and RIGHT() functions for TEXT/NTEXT fields 1

Status
Not open for further replies.

jasonsalas

IS-IT--Management
Joined
Jun 20, 2001
Messages
480
Location
GU
Hi,

I'm trying to search for a good alternative to only grab a snippetof quite large fields in my DB. I only need about the first 250 characters in an NTEXT field for a teaser.

Of course, using the LEFT(field,250) syntax won't work because that function doesn't work with fields of type NEXT/NTEXT.

Anyone got any good ideas?
 
Hi,

Try this...

SELECT LEFT(250,CAST(NtxtFLD as varchar(8000))) from TBL


Sunil
 
Good idea...but the error that's thrown now reads:

Server: Msg 245, Level 16, State 1, Line 5
Syntax error converting the varchar value.... <text listed>

Got any other ideas?
 
Actually, I think I figured it out:

LEFT(CAST(NTextfld as VARCHAR(8000)),15)

(Note the reversal of arguments for the LEFT function - the characters to return and the CASTed characters.

Thanks a lot for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top