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:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
|
SELECT n.Load_Date ,
ISNULL(d.Qty, 0) AS Qty,
b.Factory_Name,
b.Operation_Name ,
b.Total_Target
FROM ( SELECT CONVERT(VARCHAR(8), dt, 112) AS Load_Date
FROM OPENROWSET('SQLOLEDB', 'xxx'; 'x_xxx'; 'xxxx',
'SELECT * FROM RTC.dbo.Corp_Calendar') AS Load_Date
WHERE ( dt >= DATEADD(M, DATEDIFF(M, 0, GETDATE()), 0) )
AND ( dt < DATEADD(M, DATEDIFF(M, 0, GETDATE()) + 1, 0) )
) AS n
LEFT OUTER JOIN ( SELECT CONVERT(VARCHAR(8), dbo.t_Load.Create_Datetime, 112) AS Load_Date ,
SUM(dbo.t_Load.Initial_Qty) AS Qty ,
dbo.t_Material.Work_Center_Code ,
t_Resource_1.Resource_Desc
FROM dbo.t_Item_Master
INNER JOIN dbo.t_Load ON dbo.t_Load.MMM_Facility_Code = dbo.t_Item_Master.MMM_Facility_Code
AND dbo.t_Load.MMM_Id_Nbr = dbo.t_Item_Master.MMM_Id_Nbr
AND dbo.t_Load.Active_Status_Ind = 'A'
INNER JOIN dbo.t_Inventory_Event ON dbo.t_Inventory_Event.Load_Id = dbo.t_Load.Load_Id
AND dbo.t_Load.Active_Status_Ind = 'A'
INNER JOIN dbo.t_Material_In_Load ON dbo.t_Load.Load_Id = dbo.t_Material_In_Load.Load_Id
INNER JOIN dbo.t_Material ON dbo.t_Material_In_Load.Material_Id = dbo.t_Material.Material_Id
LEFT OUTER JOIN dbo.t_Resource AS t_Resource_1 ON dbo.t_Item_Master.MMM_Facility_Code = t_Resource_1.MMM_Facility_Code
AND dbo.t_Material.Work_Center_Code = t_Resource_1.Resource_Nbr
WHERE ( dbo.t_Load.MMM_Facility_Code = 'MC' )
AND ( dbo.t_Inventory_Event.Event_Type_Code = 'PRODUCE' )
AND ( dbo.t_Material.Work_Center_Code = '4624' )
AND ( CONVERT(VARCHAR(8), dbo.t_Load.Create_Datetime, 112) >= DATEADD(m,
DATEDIFF(m, 0,
GETDATE()), 0) )
AND ( CONVERT(VARCHAR(8), dbo.t_Load.Create_Datetime, 112) <= GETDATE() )
GROUP BY CONVERT(VARCHAR(8), dbo.t_Load.Create_Datetime, 112) ,
dbo.t_Material.Work_Center_Code ,
t_Resource_1.Resource_Desc
) AS d ON n.Load_Date = d.Load_Date
CROSS JOIN (SELECT Factory_Name, Operation_Name ,Total_Target
FROM OPENROWSET('SQLOLEDB', 'xxx'; 'read_xx'; 'xxx',
'SELECT Factory_Name, Operation_Name, SUM(Monthly_Target) AS Total_Target
FROM dbo.WC_Target WHERE (WC_Code = 4002) OR (WC_Code = 4003) OR (WC_Code = 4624) GROUP BY Factory_Name, Operation_Name')) b
|