Friday, 7 August 2015

Croass Tab Query in Access

Original Table: Production

PDate ItemID ItemName Made_Item Left_Item
------------------------------------------------------------
06/24/15 1 Prod1 4 1
06/24/15 2 Prod2 6
06/25/15 1 Prod1 5
06/25/15 2 Prod2 5 2


CrossTab Production: For Made Items

ItemID ItemName 06/24/15 06/25/15
----------------------------------------------------------
1 Prod1 4 5
2 Prod2 6 5

SQL Query:

--------------

TRANSFORM Sum(Production.[Made_Item]) AS SumOfMade_Item
SELECT Production.[ITemID], Production.[ItemName], Sum(Production.[Made_Item]) AS [Total Of Made_Item]
FROM Production
GROUP BY Production.[ITemID], Production.[ItemName]
PIVOT Format([PDate],"Short Date");