Is there a way to replace characters in SQL Server from a string using a mapping table and without using a loop.
I have mapping that can go like this:
a => b
b => c
...
z => a
This mapping is not static and can change. I tried the solution from https://stackoverflow.com/a/45202933/3161817 and https://stackoverflow.com/a/13051989/3161817 but I only end up having a string that are just a, like 'aaaaaaaa'
My current solution is like:
DECLARE @NextChar NCHAR(1)
DECLARE @Position int = 1
DECLARE @StrLength int = LEN(@str)
DECLARE @Result nvarchar(1000) = ''
WHILE (@Position <= @StrLength)
BEGIN
SET @NextChar = SUBSTRING(@str, @Position, 1)
SET @Result = @Result + ISNULL((SELECT ToChar FROM CharMapping
WHERE @NextChar COLLATE Latin1_General_BIN = FromChar COLLATE Latin1_General_BIN
), @NextChar)
SET @Position= @Position + 1
END
but I'm looking for a possible solution without a loop.