SQLTeam.com | Weblogs | Forums

Multiple Replacement, how to apply this syntax


I have a NVARCHAR column that I want to apply multiple replacements commands to. The words that have to be replaced (actually they are deleted by replacing them with an empty string) are listed in a TableA. I found this thread, that shows how to do this with a @parameter:

DECLARE @String varchar(max) = 'Hexagonal 28 mm'
SELECT @String = replace(@String, CriticalWord, '') from TableA
SELECT @String

I'm new to this kind of syntax and wonder how to apply that logic to a column of a TableB:

Select StringColumn from TableB

What I'm trying to do is to isolate the numeric part; as there is a limited amount of words (hexagonal, mm,..) that appear in that string and that need to deleted I came up with that idea.


I finally did it with a function although performance isn't to good.


Post your function and let's see what we can do for you.

ALTER FUNCTION [dbo].[MultiReplace]
@String nvarchar(300)
RETURNS nvarchar(300)
SELECT @String = replace(@String, CriticalWord, '') from Template_Clear
			select @String