homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

Changing just the first mention of a word in any given table?

WebmasterWorld Senior Member sgt_kickaxe us a WebmasterWorld Top Contributor of All Time

Msg#: 4344940 posted 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

UPDATE table1
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.



WebmasterWorld Senior Member 10+ Year Member

Msg#: 4344940 posted 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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved