I have a function below and also the output, it is basically to find particular letters in a string and replace them with some other letters, for example in this string abcde I want to replace de with xy, so I give @input = abcde, @find = de and @replace = xy, so I get the output as abcxy, but if assume I have a string hat and I want to replace h and t with m and c, how do i achieve this?
And I must find the solution without using a while loop in my function
create FUNCTION dbo.replace_letters
(
@Input AS VarChar(1000),
@Find AS VarChar(100),
@Replace AS VarChar(100)
)
RETURNS VarChar(1000)
AS
BEGIN
SELECT @Input = REPLACE(@Input, @Find,@Replace)
return @input
end
--run
select dbo.replace_letters ('abcde', 'ed', 'dc')