1
Declare @abc varchar(max)='5,4,1',
@xyz varchar(max)='1,2,3';

select value[A] from  string_split(@abc,',')
select value[B] from  string_split(@xyz,',')  

I need this result in same table

A   B
5   1
4   2
1   3
Dale K
  • 25,246
  • 15
  • 42
  • 71
  • Can you supply the code for string_split as well , maybe update the question with it? – Gurpreet_Carmel_5 Aug 09 '19 at 07:13
  • Possible duplicate of [Turning a Comma Separated string into individual rows](https://stackoverflow.com/questions/5493510/turning-a-comma-separated-string-into-individual-rows) – Ankit Bajpai Aug 09 '19 at 07:15
  • @AnkitBajpai: that link is creating `union` of different strings while OP wants something like `join` – DarkRob Aug 09 '19 at 07:17

1 Answers1

1

You may use row_number() to give unique number to each record of your string, then apply join on behalf of that generated row_number().
Sample is like this.

   select [A], [B] from 
   (
       select row_number() over (order by (select 100)) as Slno, value as  [A] from  string_split(@abc,',')
   ) as t1 
   full outer join 
   (
        select row_number() over (order by (select 100)) as Slno, value as  [B] from  string_split(@xyz,',')
   ) as t2 
   on t1.slno=t2.slno
DarkRob
  • 3,843
  • 1
  • 10
  • 27