# Miscellaneous > SQL Scripts >  Pivot the columns data

## marpadga18

I have oracle table which has  like below example in col7 column there will be values seperated , in one column it is kind of horizontal pivoting but the data is in 1 column seprated , 

In near future this col7 and col8 may have some more values 


col7 * col8 that many records it should create


col1| clo2| col3| col4| clo5|col7                   | col8                           
ahy |ahx  |axs  |aht  |azs  |LO1,LO2,LO3,LO4 |LH1,LH2,LH3
zas |bsz  |dgf  |asd  |ans  |LO5,LO6             |LH7

I need the ouptput like
col1 clo2 col3 col4 clo5     col7      col8                                                
ahy ahx  axs  aht  azs       LO1       LH1
ahy ahx  axs  aht  azs       LO1       LH2
ahy ahx  axs  aht  azs       LO1       LH3
ahy ahx  axs  aht  azs       LO2       LH1
ahy ahx  axs  aht  azs       LO2       LH2
ahy ahx  axs  aht  azs       LO2       LH3
ahy ahx  axs  aht  azs       LO3       LH1
ahy ahx  axs  aht  azs       LO3       LH2
ahy ahx  axs  aht  azs       LO3       LH3
ahy ahx  axs  aht  azs       LO4       LH1
ahy ahx  axs  aht  azs       LO4       LH2
ahy ahx  axs  aht  azs       LO4       LH3
zas bsz  dgf  asd  ans       LO5       LH7
zas bsz  dgf  asd  ans       LO6       LH7
I know this can be done in sql by using pivot and decode but any one could give some smaple script it would be really helpfull for me.Thank you very much

----------


## rmiao

If you use sql server, can find syntax and sample code in books online.

----------

