I am trying to find an optimally optimized way to split alternate column rows into two columns. Let me explain this with an example.
I have the following data

Result i want

in the above example, the alternate row is shifted to a new column. I came up with a solution, but it is not optimized if I have millions of records.
My solution (not optimized)
;WITH RecCtea AS ( SELECT *, ROW_NUMBER() OVER (ORDER BY (select 1)) rowid FROM tabA ta ) SELECT a.cola,b.cola FROM ( (SELECT * FROM RecCtea rc WHERE rc.rowid%2 = 0) a JOIN (SELECT * from RecCtea rc2 where rc2.rowid%2 != 0) b on a.rowid = b.rowid+1 )
SQLfiddle does not work, so here is the schema
CREATE TABLE tabA ( cola int ); INSERT tabA ( cola ) VALUES (100),(-100),(200),(-250),(300),(-350),(-400),(NULL)
source share