View Single Post

   
  #1 (permalink)  
Old 02-28-2008, 10:32 AM
mcl
 
Posts: n/a
Default Replacing ONLY the first occurence of a substring in a string

I have a field which has multiple comma characters in it and I want to
change the first occurrence only.

I can not work out how to do this as replace changes all occurrences.

eg

Field
'fred, bob, june, 12/34/56'
needs to become
'fred^ bob, june, 12/34/56'

where the first comma ',' becomes a circumflex '^'

The first comma can be in any position or not present at all

I imagine it will be something like

set field1= IF(POS(field1,','), CONCAT(substr field1 up to comma, '^',
substr field1 after comma),else field1 Unchanged)

If someone could help before I wipe my whole field I would be most
grateful.

Richard
Reply With Quote