I am trying to transform an input csv file as below and generate a new output file format using SQL. I am wondering is there a way to solve it in SQL or do I need to write code to solve this problem. Please kindly share your thoughts on this. Thank you.
Let us assume the below data is stored in a Double Dimensional Array A.
Input Data :-
0 1 2 3 4 5 6
A[0] 0 ,300 ,0 ,301 ,0 ,302, 0 --Header
A[1] 100,9011,100,9002,100,9002,100 --First Row
A[2] 101,8101, 95,2001,100,2001,100 --Second Row
A[3] 102,8101,105,2001,110,2001,100 --Third Row
Output Data :-
--First Row from input
100,300,9001,100 ( A[1][0],A[0][1],A[1][1],A[1][2] )
100,301,9002,100 ( A[1][0],A[0][3],A[1][3],A[1][4] )
100,302,9002,100 ( A[1][0],A[0][5],A[1][5],A[1][6] )
--Second Row from input
101,300,8101,95 ( A[2][0],A[0][1],A[2][1],A[2][2] )
101,301,2001,100 ( A[2][0],A[0][3],A[2][3],A[2][4] )
101,302,2001,100 ( A[2][0],A[0][5],A[2][5],A[2][6] )
--Third Row from input
102,300,8101,105 ( A[3][0],A[0][1],A[3][1],A[3][2] )
102,301,2001,110 ( A[3][0],A[0][3],A[3][3],A[3][4] )
102,302,2001,100 ( A[3][0],A[0][5],A[3][5],A[3][6] )
Note :- I tried solving it in SQL but I felt like its a tough approach.