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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Truncating Queried Text 1

Status
Not open for further replies.
Mar 10, 2005
63
US
How would I truncate the text from a field in a database.?Would that be done at the query or the ouput of the variable? Also, even though I want it truncated, I would like the full text to be used as the ALT for the link. Thanks.
 
You can get both from the query.


SELECT text AS fulltext, LEFT(text,200) AS trunctext FROM...

But the truncated text could be in the middle of a word, unless you know regex / sql magic that I am no good at :)

So you could truncate to the word with CF

SELECT text FROM...

<cfoutput query...>
#text# is full text

#listDeleteAt(ListLen(left(text,200)," ")," ")# Short Text, cut off at the word.

probably better ways to do it? It is friday...






Kevin
 
You get around Kevin. Thanks again for the help. I copied and pasted what you type, but I got an error.

The value of the parameter 2, which is currently " ", must be a int value.
 
there's a way to cut it off on a whole word in mysql, if you're interested -- the substring_index function

r937.com | rudy.ca
 
Ah ... you've been keeping that quiet Rudy .. I've been after somthing like that for ages lol ... all my current article 'Briefs' on news columns and things cut off half way through a word ... that'll come in handy.

Rob
 
It sounds fantastic,

Have you got a more thorough explanation at to how it might be used to truncate a load of text from a database field? .. just for us hopeless amatures ;-)

Ta,

Rob
 
Good man Rudy ... you've earned yourself a Purple star on that one.

Thanks again,

Rob
 
Thanks Kevin,

Whats the purpose of your #listDeleteAt(text,ListLen(left(text,200)," ")," ")# function?

I've just used Rudy's example of substring_index(mytextcolumn,' ',17) and left that second parameter as " " and it seems to be working fine. Is that the parameter you were refering too?

Thanks,

Rob
 
what's the purpose of using the listDeleteAt expression at all, if you have pulled out a whole number of words?

r937.com | rudy.ca
 
The SQL method is the way to go...

But if you don't...

What I posted takes 200 chars of the text, and cuts off the last word, which may or may not be a whole word.

The value I was refering to was in reply to highvoltage's replay about what I posted.



Kevin
 
Sorry, I didn't mention the database being used. I just wasn't sure if this could be done from the query. I am using an Oracle database. Because of this, I'll probably need to use the #listDeleteAt right?
 
oracle? you shoulda said so

i would do something like this (don't have oracle to test on) --

select left(daField,instr(daField,' ',1,17)-1)

finds the 17th blank and takes everything to the left of it

:)


r937.com | rudy.ca
 
Thanks for everyones help. I found a different way, tell me what you think.

SELECT substr(daName,1,25)

This seemed to work fine, but I don't know if it's kosher.
 
Yeah, that's fine. I'll just incorporate an elipse so people no there's more to the title. And I have a title on each link so they get a tooltip.
 
OK, I'm back. Realized I don't know how to check to if a varible has x amount of characters. I need this so I can run it through a cfif and add an elipse if necessary.
 
actually your problem is worse than you think it is

if you have a field that's 21 characters long, then taking

substring(field,1,25)

will return the entire field, and you do not want to add an ellipsis in that case

also, an ellipsis that indicates there is something more looks silly right behind a word that has been trunca...

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top