| Welcome to WebmasterWorld Guest from 220.127.116.11 |
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
|Accredited PayPal World Seller|
|Changing just the first mention of a word in any given table?|
| 11:37 am on Jul 28, 2011 (gmt 0)|
Changing EVERY iteration of a word in a table is simple with the REPLACE function. example
SET col1 = (REPLACE (col1, 'widget', 'bigwidget'))
But how would I write that to replace only the FIRST iteration of the word in the table? Or how would I make sure the word is not inside markup such as a link?
edit: in case it helps I want to replace keywords with links to their respective pages but only the first instance on any given page/table. I don't want to link the same keyword 20 times on a page.
| 11:58 am on Jul 28, 2011 (gmt 0)|
Instead of replace, you should find that INSTR should give you the position of the first word. Then you can use something along the lines of:
LEFT(col1,INSTR(col1)-1) + 'bigwidget' + MID(col1,INSTR(col1)+LENGTH(col1))
Probably not the most efficient way but it should work. It is psuedocode so you might need to lookup what should be used for LEFT, MID and LENGTH in the language you are using.
All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
© Webmaster World 1996-2014 all rights reserved