Using the function replace
Replace(FieldX,'FindString','ReplaceString') where FieldX = 'ABC'
Works fine until there is an additional match inside the string that I don't want to replace.
In my case I have an address field that I got as ALL CAPS. However I want to change 'PR' to 'Prairie' when it occurs as:
- 'PR %'
- '% PR'
- % PR %'
Yet if I do:
Update TableA
Set Address=Replace(Address,'PR','PRAIRIE')
where Address like '%PR ' or Address like 'PR %' or Address like '% PR '
Then 'PR PRIMO' becomes 'PRAIRIE PRAIRIEIMP'
I thought, even though it gets cumbersome given the extent of my changes I could solve this in three queries
Update TableA
Set Address=Replace(Address,'PR ','PRAIRIE ')
where Address like like 'PR %'
Update TableA
Set Address=Replace(Address,' PR',' PRAIRIE')
where Address like like '% PR'
Update TableA
Set Address=Replace(Address,' PR ',' PRAIRIE ')
where Address like like '% PR %'
But this will be cumbersome (again I have far more replacements to do and other issues) and seems like it could still generate errors I haven't anticipated. The replace tables are also very large and this triples the processing time.
Has anyone run into a way to solve this is a less heavy-handed approach? If this were regex I could get away with it I think but I've found regex adds a huge overhead to this type of replacement and as I said the tables are large.