Consider the problem below: I have two strings for split:
STR1 = 'b;a;c;d;e'
STR2 = '3;1;4;2;5'
I want to split and merge these two strings based on their index, such that the result is:
b -> 3
a -> 1
c -> 4
d -> 2
e -> 5
I tried with STRING_SPLIT, but order by sorts them all.
SELECT A.VALUE, B.VALUE FROM (
SELECT VALUE, ROW_NUMBER() OVER(ORDER BY VALUE) AS RW
FROM STRING_SPLIT('b;a;c;d;e', ';')
) A
INNER JOIN (
SELECT VALUE, ROW_NUMBER() OVER(ORDER BY VALUE) AS RW
FROM STRING_SPLIT('3;1;4;2;5', ';')
) B
ON A.RW = B.RW
This produces the following result:
a 1
b 2
c 3
d 4
e 5