views:

1274

answers:

2

How do you use the LEFT function (or an equivalent) on a SQL Server NTEXT column?

Basically I'm building a GridView and I just want to return the first 100 or so characters from the Description column which is NTEXT.

+3  A: 

You would have to cast it to a VARCHAR(MAX) first.

Craig
+6  A: 

SELECT CAST(ntext_col AS nvarchar(100)) as ntext_substr FROM ...

[EDIT] Originally had it returning LEFT(N,100) of CAST to nvarchar(MAX), CASTing will truncate and since LEFT is wanted, that is enough.

tvanfosson
I'd think that casting it as a NVARCHAR(100) would be enough, right? If the cast works, then the value should already be the left 100 chars.
Eric Tuttleman
thanks worked fine. is there any reason it doesn't just work without the cast?
Brian Boatright
Updated to just do the CAST. LEFT will not work on NTEXT, but CAST will truncate if longer than the length specified.
tvanfosson