Average Joe
Average Joe

Reputation: 4601

truncating a field value in a SQL select

In a SQL statement, how do you limit the returned value of a text field char length to a certain size?

Tried so far-

select len(mytextfield,30) from table

Upvotes: 1

Views: 4010

Answers (2)

datagod
datagod

Reputation: 1051

select left(mytextfield,30)

I am not positive, but I think the substring function does not work against the TEXT datatype.

Upvotes: 1

Jeremy Wiggins
Jeremy Wiggins

Reputation: 7299

You want the SUBSTRING function.

SELECT SUBSTRING(mytextfield, 1, 30) FROM Table

(This is assuming SQL Sever / T-SQL; you didn't specify a database engine.)

Upvotes: 4

Related Questions