Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using LEFT on a TEXT-field in SQL Server

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?

like image 333
Kjensen Avatar asked Dec 08 '22 06:12

Kjensen


2 Answers

instead of left . try with SUBSTRING

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

like image 79
anishMarokey Avatar answered Dec 28 '22 01:12

anishMarokey


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) .....
like image 21
marc_s Avatar answered Dec 28 '22 02:12

marc_s