Hi everybody!
I've been strugling with this query for some time when I first created it. And after slight modification it does not work again! And I don't know what to do...
So, here it is:
The working one:
SQL = "SELECT HumanRes.WeekNumber AS [Week_#], " & _
"HumanRes.HeadCount AS H_Count, " & _
"HumanRes.LostTime, " & _
"ModuleTime.ModulesCount AS Mod_Qty, " & _
"Format(H_Count*0.9028,'0.0') AS Capacity, " & _
"Format((H_Count*32.5-[LostTime])*(1/36),'0.0') AS Actual_Cty, " & _
"Format((Mod_Qty/(H_Count * 0.9028)) * 100,'0.0') AS Gen_Eff, " & _
"Format((Mod_Qty/Actual_Cty)*100,'0.0') AS Actual_Eff " & _
"FROM (SELECT Sum(Format(([Module].[Ship Date]-[Module].[Kit-Up Date])*24,'0.0')) " & _
"AS [Cycle Time], Count(*) AS ModulesCount, DatePart('ww',[Module].[Ship Date])-1 " & _
"AS WeekNumber FROM [Module] WHERE (DatePart('yyyy',[Module].[Ship Date])= " & Year & " " & _
"AND (Module.[Ship Date] Is Not Null)) " & _
"GROUP BY DatePart('ww',[Module].[Ship Date])-1) AS ModuleTime " & _
"INNER JOIN (SELECT HumanResourses.WeekNumber, HumanResourses.HeadCount, " & _
"HumanResourses.LostTime From HumanResourses " & _
"WHERE (((HumanResourses.YearNumber)= " & Year & ")) AS HumanRes " & _
"ON ModuleTime.WeekNumber = HumanRes.WeekNumber " & _
"WHERE (((HumanRes.WeekNumber) Between " & StartWeek & " And " & EndWeek & ")"
This one does not work giving me error "SELECT' operator is missing or incorrect reserved word"
If tags allowed modified parts will be in bold.
SQL = "SELECT HumanRes.WeekNumber AS [Week_#], " & _
"HumanRes.HeadCount AS H_Count, " & _
"HumanRes.LostTime, HumanRes.WeekHours " & _
"ModuleTime.ModulesCount AS Mod_Qty, " & _
"Format(H_Count*(HumanRes.WeekHours/36),'0.0') AS Capacity, " & _
"Format((H_Count*<b>HumanRes.WeekHours</b>-LostTime)*(1/36),'0.0') AS Actual_Cty, " & _
"Format((Mod_Qty/(H_Count * (HumanRes.WeekHours/36))) * 100,'0.0') AS Gen_Eff, " & _
"Format((Mod_Qty/Actual_Cty)*100,'0.0') AS Actual_Eff " & _
"FROM (SELECT Sum(Format((Module.[Ship Date]-Module.[Kit-Up Date])*24,'0.0')) " & _
"AS [Cycle Time], Count(*) AS ModulesCount, DatePart('ww',Module.[Ship Date])-1 " & _
"AS WeekNumber FROM Module WHERE (DatePart('yyyy',Module.[Ship Date])= " & Year & " " & _
"AND (Module.[Ship Date] Is Not Null)) " & _
"GROUP BY DatePart('ww',Module.[Ship Date])-1) AS ModuleTime " & _
"INNER JOIN (SELECT HumanResourses.WeekNumber, HumanResourses.HeadCount, " & _
"HumanResourses.LostTime, HumanResourses.WeekHours From HumanResourses " & _
"WHERE (((HumanResourses.YearNumber)= " & Year & ")) AS HumanRes " & _
"ON ModuleTime.WeekNumber = HumanRes.WeekNumber " & _
"WHERE (((HumanRes.WeekNumber) Between " & StartWeek & " And " & EndWeek & ")"
I've been strugling with this query for some time when I first created it. And after slight modification it does not work again! And I don't know what to do...
So, here it is:
The working one:
SQL = "SELECT HumanRes.WeekNumber AS [Week_#], " & _
"HumanRes.HeadCount AS H_Count, " & _
"HumanRes.LostTime, " & _
"ModuleTime.ModulesCount AS Mod_Qty, " & _
"Format(H_Count*0.9028,'0.0') AS Capacity, " & _
"Format((H_Count*32.5-[LostTime])*(1/36),'0.0') AS Actual_Cty, " & _
"Format((Mod_Qty/(H_Count * 0.9028)) * 100,'0.0') AS Gen_Eff, " & _
"Format((Mod_Qty/Actual_Cty)*100,'0.0') AS Actual_Eff " & _
"FROM (SELECT Sum(Format(([Module].[Ship Date]-[Module].[Kit-Up Date])*24,'0.0')) " & _
"AS [Cycle Time], Count(*) AS ModulesCount, DatePart('ww',[Module].[Ship Date])-1 " & _
"AS WeekNumber FROM [Module] WHERE (DatePart('yyyy',[Module].[Ship Date])= " & Year & " " & _
"AND (Module.[Ship Date] Is Not Null)) " & _
"GROUP BY DatePart('ww',[Module].[Ship Date])-1) AS ModuleTime " & _
"INNER JOIN (SELECT HumanResourses.WeekNumber, HumanResourses.HeadCount, " & _
"HumanResourses.LostTime From HumanResourses " & _
"WHERE (((HumanResourses.YearNumber)= " & Year & ")) AS HumanRes " & _
"ON ModuleTime.WeekNumber = HumanRes.WeekNumber " & _
"WHERE (((HumanRes.WeekNumber) Between " & StartWeek & " And " & EndWeek & ")"
This one does not work giving me error "SELECT' operator is missing or incorrect reserved word"
If tags allowed modified parts will be in bold.
SQL = "SELECT HumanRes.WeekNumber AS [Week_#], " & _
"HumanRes.HeadCount AS H_Count, " & _
"HumanRes.LostTime, HumanRes.WeekHours " & _
"ModuleTime.ModulesCount AS Mod_Qty, " & _
"Format(H_Count*(HumanRes.WeekHours/36),'0.0') AS Capacity, " & _
"Format((H_Count*<b>HumanRes.WeekHours</b>-LostTime)*(1/36),'0.0') AS Actual_Cty, " & _
"Format((Mod_Qty/(H_Count * (HumanRes.WeekHours/36))) * 100,'0.0') AS Gen_Eff, " & _
"Format((Mod_Qty/Actual_Cty)*100,'0.0') AS Actual_Eff " & _
"FROM (SELECT Sum(Format((Module.[Ship Date]-Module.[Kit-Up Date])*24,'0.0')) " & _
"AS [Cycle Time], Count(*) AS ModulesCount, DatePart('ww',Module.[Ship Date])-1 " & _
"AS WeekNumber FROM Module WHERE (DatePart('yyyy',Module.[Ship Date])= " & Year & " " & _
"AND (Module.[Ship Date] Is Not Null)) " & _
"GROUP BY DatePart('ww',Module.[Ship Date])-1) AS ModuleTime " & _
"INNER JOIN (SELECT HumanResourses.WeekNumber, HumanResourses.HeadCount, " & _
"HumanResourses.LostTime, HumanResourses.WeekHours From HumanResourses " & _
"WHERE (((HumanResourses.YearNumber)= " & Year & ")) AS HumanRes " & _
"ON ModuleTime.WeekNumber = HumanRes.WeekNumber " & _
"WHERE (((HumanRes.WeekNumber) Between " & StartWeek & " And " & EndWeek & ")"