REPLACE

REPLACE
Published: Oct 07, 2013
This is a very common function when performing string manipulation… you simply pass in a character or string that you wish SQL to look for, the text in which to look, and what you want the character or string replacing with.

Character replace



declare @text varchar(40)
set @text = 'mom'

select replace(@text, 'm', 'b')


String replace



declare @text varchar(40)
set @text = 'flash'

select replace(@text, 'la', 'i')


Need Help With Your SQL Server?

If this article raised questions about your own SQL Server estate, we offer a free no-obligation health check. Let us take a look.

Get Your Free Health Check
An unhandled error has occurred. Reload 🗙