I have read the stuff on MS pivot tables and I am still having problems getting this correct.
I have a view with these results
Invoice Date Basecard Item Quantity Subtotal Taxes Total
713938 09/11/2020 C90001 Desktop 14 2800 448 3248
713938 09/11/2020 C90001 Laptop 18.5 29091.25 4654.6 33745.85
I would like it to come out as a pivot table, like this:
Invoice Date Basecard Laptop Desktop Subtotal Taxes Total
713938 09/11/2020 C90001 18.5 14 31891.25 5102.6 36993.85
This is my query
SELECT * FROM (
SELECT Invoice, Date, BaseCard, Item, sum(Quantity) Qty, sum(Subtotal) Subtotal
FROM MyView
Group by Invoice, Date, BaseCard, Item, Subtotal
) Resultados
PIVOT (
Sum(Qty)
FOR Item
IN (
[Laptop], [Desktop]
)
) AS PivorTable
Group by Invoice, Date, BaseCard, Laptop, Desktop, Subtotal
The result
Invoice Date baseCard subtotal Laptop Desktop
713938 2020-11-09 C90001 2800.00 NULL 14.000000
713938 2020-11-09 C90001 7076.25 4.50 NULL
713938 2020-11-09 C90001 22015.000 14.00 NULL