I have a string and i would like to replace some words in it by referring a lookup table
create table LookupTab
(
oldvalue varchar(100),
newvalue varchar(100)
);
insert into LookupTab
values ('Run', 'Run Go'), ('Hide', 'Hide Mask'), ('Go', 'Go Run'), ('Mask', 'Mask Hide')
Expected output
string ='i have to go'
result ='i have to Go Run' <-- it should not again replace the word Run
string ='i have to go and go again'
result ='i have to Go Run and Go Run again'
What I have tried
CREATE FUNCTION [dbo].[TranslateString]
(@Str nvarchar(max))
RETURNS nvarchar(max)
AS
BEGIN
DECLARE @Result nvarchar(max) = @Str;
SELECT @Result = REPLACE(@Result, Oldvalue, NewValue)
FROM LookupTab;
RETURN @Result;
END
but it replaces the replaced word again


values()portion of theinsertmust be in single quotes!insert into LookupTab(oldvalue, newvalue) values ('Run', 'Run Go'), .....goandGo, Go Run. Is this important?