0

Is there any other way to replace multiple strings in sql server 2008r2? which is also fast?

My query is below.

Select REPLACE(REPLACE(EmailText,'#{Name}#',UV.Name),'#{organisation}#',CV.Organisation)

I am written it with example also

Select REPLACE(REPLACE('Hi #{Name}# from #{organisation}#','#{Name}#','Jhon'),'#{organisation}#','Cocacola')
user2972061
  • 305
  • 1
  • 5
  • 17
  • Other than using a clr function, sql server does not support regular expressions. Replace is probably the best way to do it. – Zohar Peled Aug 17 '17 at 06:42

1 Answers1

2

There are all sorts of ways:

But 'best' as in 'fastest' is probably going to be using REPLACE Repeatedly, as all the attempts in these links have some limitation..

Caius Jard
  • 72,509
  • 5
  • 49
  • 80
  • are you sure Replace is fast? I means if i will replace 5 to 6 strings, it wouldn't slow down the select statement? – user2972061 Aug 17 '17 at 06:54
  • 1
    Depends what you mean by fast. Sqlserver can replace your strings faster than I can replace strings with a pencil and paper?! Of course any additional processing of data will reduce the rate at which results can be produced, but your question doesn't really make sense because you're asking for absolute when this operation is relative. If you have a million replacements to make, you have to make them somehow, and it's going to take some time. So go make them with replace, and if it's too slow, try something else from these links. I think you'll come back to using replace in the end though – Caius Jard Aug 17 '17 at 06:58