Jump to content

Tricky Query Help....is this even possible? (I love laying down a challenge)


bassmo

Recommended Posts

Hi all,

 

I have a rather annoying problem.  I need to be able to run a replace on a string.  In itself obviously not a problem.  However I only need to replace the occurrence of the string when it is at the start of the string.  Example:

 

Need to replace Apple with Orange:

 

AppleBananaPeach      to become  OrangeBananaPeach

ApplePearPlumApple    to become  OrangePearPlumApple

BananaApple                to remain  BananaApple

 

All strings are a single "word", no spaces.

 

The thought occurs to me to place a marker at the start.  Something along the lines of:

 

|ApplePearPlumApple      ->  Replace      |Apple with Orange    ->    OrangePearPlumApple

 

Any idea if I can do this?

 

Many thanks in advance.

 

Bassmo / Jon

Link to comment
Share on other sites

Or if you only want to show a different word without changing the data in the table you could use this, handy for masking the start of sensetive information, such as card no's and the like

SELECT REPLACE((SELECT `text` FROM table where left(`text`, Length('WordToReplace')) = 'WordToReplace'), 'WordToReplace', 'NewWord')

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.