0

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.

Teja
  • 13,214
  • 36
  • 93
  • 155
  • I removed the incompatible database tags. Please tag only with the database you are really using. – Gordon Linoff Sep 05 '17 at 19:02
  • I am trying to solve this problem in SQL Server. – Teja Sep 05 '17 at 19:03
  • Your goal is confusing. Can you post your **syntax** and what your requirements you need for your output? It doesn't make any sense. Are they suppose to be in an order of Lowest value to Highest? – Isaiah3015 Sep 05 '17 at 19:11
  • I will keep my input and output simpler. Just updated the question. pls check. – Teja Sep 05 '17 at 19:14
  • Isn't this the same question you're asking here https://stackoverflow.com/questions/46063269/split-a-single-row-into-multiple-rows-using-sql? – Jason A. Long Sep 05 '17 at 23:16

0 Answers0