asusetyo
Board Regular
- Joined
- Feb 18, 2014
- Messages
- 50
Hi All,
Good Morning from Indonesia,
Sorry, please bear with the code
So basically this Code works, and I want to put another complicated (*for me) field
I have Stock_On_Hand form table ZinQ Template, but I have difficulty to generate National_Stock_On_Hand
Logic of National_Stock_On_Hand is just by sum-ing Stock_On_Hand based on Week & Product Code in table ZinQ Template, (*sum-ing all Plant)
Thanks before,
Aditeyo
Good Morning from Indonesia,
Sorry, please bear with the code
So basically this Code works, and I want to put another complicated (*for me) field
I have Stock_On_Hand form table ZinQ Template, but I have difficulty to generate National_Stock_On_Hand
Logic of National_Stock_On_Hand is just by sum-ing Stock_On_Hand based on Week & Product Code in table ZinQ Template, (*sum-ing all Plant)
Code:
SELECT Left([Week],7) AS APL_Month,
[ZinQ Template].Week AS APL_Week,
[Principal Master].[Division Code],
[Principal Master].[Division Name],
[Principal Master].[Principal Name],
[ZinQ Template].[Product Code],
[ZinQ Template].[Product Description],
[ZinQ Template].Plant,
[Branch Master].[Fac# Description],
Sum([Forecast Template].[Forecast Qty]) AS Forecast_Qty,
Sum([Forecast Template].[Forecast Value]) AS Forecast_Value,
Sum([ZinQ Template].[Stock On Hand]) AS Stock_On_Hand,
Sum([ZinQ Template].Intransit) AS Intransit_Stock,
Sum([ZinQ Template].[AMS 3]) AS AMS_3,
Sum([ZinQ Template].[Safe Stock]) AS Safety_Stock,
Sum([Order Template].[PO Qty]) AS PO_Qty,
Sum([Order Template].[Invoice Qty]) AS Invoice_Qty,
Sum([Order Template].[Loss Qty]) AS Loss_Qty,
Sum([Order Template].[PO Value]) AS PO_Value,
Sum([Order Template].[Invoice Value]) AS Invoice_Value,
Sum([Order Template].[Loss Value]) AS Loss_Value,
Sum([Order Template].[Loss Qty - Partial Complete]) AS [Loss_Qty - Partial Complete],
Sum([Order Template].[Loss Qty - Reject StockOut]) AS [Loss_Qty - Reject StockOut],
Sum([Order Template].[Loss Qty - Reject by Finance]) AS [Loss_Qty - Reject by Finance],
Sum([Order Template].[Loss Qty - Reject Others]) AS [Loss_Qty - Reject Others],
Sum([Order Template].[Loss Qty - Work in progress Finance]) AS [Loss_Qty - Work in progress Finance],
Sum([Order Template].[Loss Qty - Work in Progress Logistic]) AS [Loss_Qty - Work in Progress Logistic]
FROM [Principal Master]
INNER JOIN ([Product Master]
INNER JOIN (([Order Template]
RIGHT JOIN ([Forecast Template]
RIGHT JOIN [ZinQ Template]
ON [Forecast Template].Lookup = [ZinQ Template].Lookup)
ON [Order Template].Lookup = [ZinQ Template].Lookup)
INNER JOIN [Branch Master]
ON [ZinQ Template].Plant = [Branch Master].[Facility Code])
ON [Product Master].MATERIAL = [ZinQ Template].[Product Code])
ON [Principal Master].[Division Code] = [Product Master].DV
GROUP BY Left([Week],7), [ZinQ Template].Week, [Principal Master].[Division Code],
[Principal Master].[Division Name], [Principal Master].[Principal Name],
[ZinQ Template].[Product Code], [ZinQ Template].[Product Description],
[ZinQ Template].Plant, [Branch Master].[Fac# Description]
ORDER BY [ZinQ Template].Week, [Principal Master].[Division Code],
[ZinQ Template].[Product Code], [ZinQ Template].Plant;
Thanks before,
Aditeyo