I have this Cross Reference Consultation that gives me the units per month and year and it works perfectly, what I would like is to be able to add all the months in the same Row as Total, being able to add [1], [2], [3 ] .... At the end of the row. Thank you very much in advance
select anio, [1] Ene, [2] Feb, [3] Mar, [4] Abr, [5] May, [6] Jun,
[7] Jul, [8] Ago, [9] Sep, [10] Oct, [11] Nov, [12] Dic, [13] Total
from (
-- select inicial, a pivotar. Podría ser una tabla
select year(O.Fecha) as anio, month(O.Fecha) as Mes,
D.Unitats as Cantidad
from [Linpediv] D inner join Cabpediv O on D.Pedido = O.PEDIDO
where O.Fecha between '20000101' and '20171231'
) V PIVOT ( sum(Cantidad) FOR Mes IN ([1], [2], [3], [4], [5],
[6], [7], [8], [9], [10], [11], [12], [13]) ) as PT