I got solution with recursive CTE and FOR XML PATH:
DECLARE @n int = 4 --Add 4 for each ASCII
--Here I simulate your table, hope you have ids in it
-- because I used to join it with values
;WITH YourTable AS (
SELECT CAST(SomeString as nvarchar(max)) as SomeString
FROM (VALUES ('ABCD'),('1234'),('A1B2'),('WXYZ')
) as t(SomeString)
), cte AS (--Here we replace chars
SELECT CHAR(ASCII(SUBSTRING(SomeString,1,1))+@n) as d,
1 as [level],
LEN(SomeString) as l,
SomeString as OrigString
FROM YourTable
UNION ALL
SELECT CHAR(ASCII(SUBSTRING(OrigString,[level]+1,1))+@n),
[level]+1,
l,
OrigString
FROM cte
WHERE l >= [level]+1)
--Final output
SELECT DISTINCT c.OrigString,
(SELECT d+''
FROM cte
WHERE c.OrigString = OrigString
FOR XML PATH('')
) as NewString
FROM cte c
OPTION (MAXRECURSION 0)
Output:
OrigString NewString
1234 5678
A1B2 E5F6
ABCD EFGH
WXYZ [\]^
EDIT
Solution with VARBINARY(MAX) transformations:
DECLARE @x xml,
@n int = 4 --Add 4 for each ASCII
--Here I simulate your table, hope you have ids in it
-- because I used to join it with values
;WITH YourTable AS (
SELECT CAST(SomeString as nvarchar(max)) as SomeString
FROM (VALUES ('ABCD'),('1234'),('A1B2'),('WXYZ')
) as t(SomeString)
)
SELECT @x = (
SELECT CAST('<row str="'+SomeString+'"><p>'+REPLACE(REPLACE(CONVERT(nvarchar(max),CONVERT(VARBINARY(MAX),SomeString),1),'0x',''),'00','</p><p>')+'</p></row>' as xml)
FROM YourTable
FOR XML PATH('')
)
;WITH cte AS(
SELECT t.c.value('../@str','nvarchar(max)') as OrigString,
CHAR(CAST(CONVERT(VARBINARY(2),'0x'+t.c.value('.','nvarchar(2)'),1) as int)+@n) as NewValues
FROM @x.nodes('/row/p') as t(c)
)
SELECT DISTINCT
c.OrigString,
LEFT((
SELECT NewValues +''
FROM cte
WHERE OrigString = c.OrigString
FOR XML PATH('')
),LEN(c.OrigString)) as NewString
FROM cte c
Same output.