SQLTeam.com | Weblogs | Forums

Multiple Replacement, how to apply this syntax


#1

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.


#2

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


#3

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


#4
ALTER FUNCTION [dbo].[MultiReplace]
(
@String nvarchar(300)
  )
RETURNS nvarchar(300)
AS
BEGIN
SELECT @String = replace(@String, CriticalWord, '') from Template_Clear
RETURN  (
			select @String
        )
END