views:

153

answers:

2

In a table, I have a text-field. I need to be able to select only the first 200 chars of the field - but LEFT does not work with TEXT-fields.

What to do?

+2  A: 

You cannot apply string manipulation functions on TEXT fields - you should stop using TEXT anyway, since it will be removed from SQL Server soon!

What you can do is convert your TEXT column to VARCHAR(MAX) And then use the string gfunction:

SELECT LEFT(CAST(YourTextCol AS VARCHAR(MAX), 200) .....

Marc

marc_s
+2  A: 

instead of left . try with SUBSTRING

e.g : select SUBSTRING(TEXT,1,200) from dbo.tblText

anishmarokey
interesting! I didn't think SUBSTRING would work on a TEXT column - but it does indeed! I'm amazed.......
marc_s
its working :) . i tested
anishmarokey
Awesome! Strange that substring works, but not left. I would think LEFT implemented Subtext to do the grunt work.
Kjensen
Left wont work . i tried . y only LEFT ?
anishmarokey