How do you use LEFT for a SQL Server NTEXT column?

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

I basically create a GridView, and I just want to return the first 100 or so characters from the description column, which is NTEXT.

+4
source share
3 answers

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

[EDIT] It originally returned LEFT (N, 100) CAST to nvarchar (MAX), CASTing will be truncated, and since LEFT is required, this is enough.

+7
source

You must first transfer it to VARCHAR (MAX).

+3
source

You can use the SUBSTRING function, which "returns part of a character, binary, text or image":

SUBSTRING ( value_expression , start_expression , length_expression ) 

So, to select the first 100 characters from the Description NTEXT column, you should use something like the following:

 SELECT SUBSTRING(Description, 1, 100) as truncatedDescription FROM MyTable; 
+2
source

All Articles