Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Limiting the amount of text returned for a column within a select 1

Status
Not open for further replies.
Jun 9, 2006
159
US
Hello,

How can I limit the amount of characters that comes back in a SQL query from a column with a value type of TEXT?

For example, if this column contains a blog entry that is 17,000 chars long I want to show just the first 400 characters.

Thanks,

-- shawn

Shawn Molloy
Seattle, WA
 
SELECT SUBSTRING(blog_entry FROM 1 FOR 400) AS LimitedText

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I'm getting a error at FROM on the first line from this query:

select a.datePosted, a.title, substring(A.body FROM 1 FOR 400) AS blogEntry, b.blogname
from blog_post
inner join blog b on a.blogid=b.blogid

Shawn Molloy
Seattle, WA
 
PHV gave you ANSI SQL which is what this forum is. If you are using SQL Server then
Code:
select a.datePosted, a.title, substring(A.body,1,400) AS blogEntry, b.blogname 
from blog_post
inner join blog b on a.blogid=b.blogid
and if it's Access
Code:
select a.datePosted, a.title, Mid(A.body,1,400) AS blogEntry, b.blogname 
from blog_post
inner join blog b on a.blogid=b.blogid
 
Ah ok I thougth the FROM/FOR syntax looked kind of strange. I'll post in MS SQL fourm next time :)

Thanks.

Shawn Molloy
Seattle, WA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top