Unpivot de Tabla, Unpivot de Pivot Sql server
Hola a todos, bueno despues de ver el pivot , aqui te dejo el codigo para hacer el unpivot de una tabla, que es lo que dice el nombre, desagrupar los datos ordenados en columnas.
Te recomiendo que veas el video aun asi como siempre te dejo el codigo a continuacion.
Aqui el codigo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
--- Tabla temporta Select Cliente,[2010],[2011],[2012],[2013],[2014],[2015],[2016],[2017] into TablaTempParaUnpivot from from tempventas pivot( sum(importe) for año in ([2010],[2011],[2012],[2013],[2014],[2015],[2016],[2017]) ) as TablaTempPIVOT --- UNPIVOT DE PIVOT Select cliente, año,importe from ( Select Cliente,[2010],[2011],[2012],[2013],[2014],[2015],[2016],[2017] from tempventas pivot( sum(importe) for año in ([2010],[2011],[2012],[2013],[2014],[2015],[2016],[2017]) ) as TablaTempPIVOT) as TBPIVOT Unpivot ( importe for año in([2010],[2011],[2012],[2013],[2014],[2015],[2016],[2017]) ) as xc --UNION Union all ---UNPIVOT DE TABLA select cliente,año,importe from TablaTempParaUnpivot unpivot( importe for año in([2010],[2011],[2012],[2013],[2014],[2015],[2016],[2017]) ) as xc |
Y si te gustas, registrate a la web y o suscribete a mi canal de youtube.