0

I have a question around turning multiple rows (with multiple columns) into a single row with columns.

e.g.

Col1  Col2  Col3  
1     type1 123  
1     type2 456  

Output should be:

Col1  Col2  Col3  Col4  Col5  
1     type1  123  type2 456

I have tried looking into SQL Server recursive and Pivot but not sure which would be the correct way to proceed.

Another requirement would be to keep it as dynamic as possible.

sagi
  • 40,026
  • 6
  • 59
  • 84
Jayz
  • 11
  • 2
  • 1
    You always have two types? or they are unlimited – sagi Feb 18 '16 at 14:36
  • Maximum could be for 5 and col3 will always be different – Jayz Feb 18 '16 at 14:58
  • Look at this [answer](http://stackoverflow.com/a/35350343/243373) I gave on a somewhat similar question, see if you can make it work for your case. – TT. Feb 18 '16 at 15:28
  • Hi TT, The solution works well for a single column, but in my case there are two columns which needs to be transposed. Since pivot only gives you option to use aggregate functions, it somehow doesn't seem to work on two columns at once. – Jayz Feb 18 '16 at 15:31

0 Answers0