FueledbyAccess
New member
- Local time
- Today, 06:22
- Joined
- Sep 6, 2019
- Messages
- 6
Hello,
I'm hoping someone can help to get my query to run. At work I've inherited a database and now need to add a new year to the query that calculates hourly rates.
Below is the query I've updated, the line I added is highlighted red. However I get a 'Syntax error (missing operator) in query expression' message
SELECT '' AS [Nominal Code], datevalue(t1.Date) AS DayDate, month(t1.Date) AS [Month], '' AS [Header Ref], '' AS [Internal Ref], t2.Resource_ID & ' ' & T2.Name AS Supplier, year( t1.Date) AS [Year], t1.[Project Code] AS Project, t1.[Cost Centre Code] AS Task, t1.ProjectCentreID AS TaskKey, t1.ApprovalStatus AS [Detail Line], datevalue(t1.Date) AS Required, '_Staff' AS OrderNumber, datevalue(t1.Date) AS [Order Date], t2.Resource_ID AS [Entered by], '' AS [Line Number], iif(t3.Portfolio ='OVERHEAD', 0,
iif( DateValue(t1.Date) < datevalue('01/01/2019'), iif(t1.Price = 0, 0, 90),
iif(t2.Type = 'GRADUATE SECONDEE', 0,
iif( t2.team in ('QA AND H&S', 'SC&P-C&S','APPLIED TECH COMMERI') ,0,
switch(
DateValue(t1.Date) < datevalue('01/01/2020'), iif( t4.[User Sort 2] in ('MACHINE SHOP', 'PRODUCTION - HX MANU','SC&P-MANUF OPERATION','SC&P-MACHINISTS'), 65, 80),
DateValue(t1.Date) < datevalue('01/01/2021'), iif( t4.[User Sort 2] in ('MACHINE SHOP', 'PRODUCTION - HX MANU','SC&P-MANUF OPERATION','SC&P-MACHINISTS'), 65, t4.[Resource Price 1]),
DateValue(t1.Date) < datevalue('01/01/2022'), iif( t2.Team in ('MACHINE SHOP', 'PRODUCTION - HX MANU','SC&P-MANUF OPERATION', ‘SC&P-Man Ops & Tech’,'SC&P-TECHNICAL','SC&P-MACHINISTS'), 68, 98),
DateValue(t1.Date) >= datevalue('01/01/2022'), iif( t2.Team in ('MACHINE SHOP', 'PRODUCTION - HX MANU','SC&P-MANUF OPERATION',’ SC&P-Man Ops & Tech’, 'SC&P-TECHNICAL','SC&P-MACHINISTS'), 62, 92)
))))))* t1.Quantity AS Net, t1.Quantity AS Hours, '' AS [Nominal Account Name], 'Labour' AS CostType1, iif((T2.Type)='', 'EMPLOYEE' ,
iif(T2.Type='Contractor',
'SUBCONTRACTOR',T2.Type)) AS Cost_Type2, T2.Team AS Cost_Type3, t2.CostCentre AS GroupCostCentre, iif( t3.[Project Code] = '998','Leave', iif( t3.[Portfolio] = 'OVERHEAD', 'Overhead', 'Productive')) AS Hrs_type, iif( t2.team in ('ADMIN SUPPORT','COMPANY MANAGEMENT','FACILITIES','FINANCE','HR','IT','LEGAL & EC','MARKETING','SUPPLY CHAIN'), 'Support Functions', 'Productive Functions') AS Function_type
FROM ((prep_act_time1 AS t1 LEFT JOIN Resources AS t2 ON t1.[Resource Code] = t2.[Resource Code]) LEFT JOIN 2019_Cost_rates_data AS t4 ON t1.[Resource Code] = t4.[Resource Code]) LEFT JOIN Ref_Project_Task AS t3 ON t1.ProjectCentreID = t3.Key;
This is the original query which works fine
SELECT '' AS [Nominal Code], datevalue(t1.Date) AS DayDate, month(t1.Date) AS [Month], '' AS [Header Ref], '' AS [Internal Ref], t2.Resource_ID & ' ' & T2.Name AS Supplier, year( t1.Date) AS [Year], t1.[Project Code] AS Project, t1.[Cost Centre Code] AS Task, t1.ProjectCentreID AS TaskKey, t1.ApprovalStatus AS [Detail Line], datevalue(t1.Date) AS Required, '_Staff' AS OrderNumber, datevalue(t1.Date) AS [Order Date], t2.Resource_ID AS [Entered by], '' AS [Line Number], iif(t3.Portfolio ='OVERHEAD', 0,
iif( DateValue(t1.Date) < datevalue('01/01/2019'), iif(t1.Price = 0, 0, 90),
iif(t2.Type = 'GRADUATE SECONDEE', 0,
iif( t2.team in ('QA AND H&S', 'SC&P-C&S','APPLIED TECH COMMERI') ,0,
switch(
DateValue(t1.Date) < datevalue('01/01/2020'), iif( t4.[User Sort 2] in ('MACHINE SHOP', 'PRODUCTION - HX MANU','SC&P-MANUF OPERATION','SC&P-MACHINISTS'), 65, 80),
DateValue(t1.Date) < datevalue('01/01/2021'), iif( t4.[User Sort 2] in ('MACHINE SHOP', 'PRODUCTION - HX MANU','SC&P-MANUF OPERATION','SC&P-MACHINISTS'), 65, t4.[Resource Price 1]),
DateValue(t1.Date) >= datevalue('01/01/2021'), iif( t2.Team in ('MACHINE SHOP', 'PRODUCTION - HX MANU','SC&P-MANUF OPERATION', 'SC&P-TECHNICAL','SC&P-MACHINISTS'), 68, 98)
)))))* t1.Quantity AS Net, t1.Quantity AS Hours, '' AS [Nominal Account Name], 'Labour' AS CostType1, iif((T2.Type)='', 'EMPLOYEE' ,
iif(T2.Type='Contractor',
'SUBCONTRACTOR',T2.Type)) AS Cost_Type2, T2.Team AS Cost_Type3, t2.CostCentre AS GroupCostCentre, iif( t3.[Project Code] = '998','Leave', iif( t3.[Portfolio] = 'OVERHEAD', 'Overhead', 'Productive')) AS Hrs_type, iif( t2.team in ('ADMIN SUPPORT','COMPANY MANAGEMENT','FACILITIES','FINANCE','HR','IT','LEGAL & EC','MARKETING','SUPPLY CHAIN'), 'Support Functions', 'Productive Functions') AS Function_type
FROM ((prep_act_time1 AS t1 LEFT JOIN Resources AS t2 ON t1.[Resource Code] = t2.[Resource Code]) LEFT JOIN 2019_Cost_rates_data AS t4 ON t1.[Resource Code] = t4.[Resource Code]) LEFT JOIN Ref_Project_Task AS t3 ON t1.ProjectCentreID = t3.Key;
I'm hoping someone can help to get my query to run. At work I've inherited a database and now need to add a new year to the query that calculates hourly rates.
Below is the query I've updated, the line I added is highlighted red. However I get a 'Syntax error (missing operator) in query expression' message
SELECT '' AS [Nominal Code], datevalue(t1.Date) AS DayDate, month(t1.Date) AS [Month], '' AS [Header Ref], '' AS [Internal Ref], t2.Resource_ID & ' ' & T2.Name AS Supplier, year( t1.Date) AS [Year], t1.[Project Code] AS Project, t1.[Cost Centre Code] AS Task, t1.ProjectCentreID AS TaskKey, t1.ApprovalStatus AS [Detail Line], datevalue(t1.Date) AS Required, '_Staff' AS OrderNumber, datevalue(t1.Date) AS [Order Date], t2.Resource_ID AS [Entered by], '' AS [Line Number], iif(t3.Portfolio ='OVERHEAD', 0,
iif( DateValue(t1.Date) < datevalue('01/01/2019'), iif(t1.Price = 0, 0, 90),
iif(t2.Type = 'GRADUATE SECONDEE', 0,
iif( t2.team in ('QA AND H&S', 'SC&P-C&S','APPLIED TECH COMMERI') ,0,
switch(
DateValue(t1.Date) < datevalue('01/01/2020'), iif( t4.[User Sort 2] in ('MACHINE SHOP', 'PRODUCTION - HX MANU','SC&P-MANUF OPERATION','SC&P-MACHINISTS'), 65, 80),
DateValue(t1.Date) < datevalue('01/01/2021'), iif( t4.[User Sort 2] in ('MACHINE SHOP', 'PRODUCTION - HX MANU','SC&P-MANUF OPERATION','SC&P-MACHINISTS'), 65, t4.[Resource Price 1]),
DateValue(t1.Date) < datevalue('01/01/2022'), iif( t2.Team in ('MACHINE SHOP', 'PRODUCTION - HX MANU','SC&P-MANUF OPERATION', ‘SC&P-Man Ops & Tech’,'SC&P-TECHNICAL','SC&P-MACHINISTS'), 68, 98),
DateValue(t1.Date) >= datevalue('01/01/2022'), iif( t2.Team in ('MACHINE SHOP', 'PRODUCTION - HX MANU','SC&P-MANUF OPERATION',’ SC&P-Man Ops & Tech’, 'SC&P-TECHNICAL','SC&P-MACHINISTS'), 62, 92)
))))))* t1.Quantity AS Net, t1.Quantity AS Hours, '' AS [Nominal Account Name], 'Labour' AS CostType1, iif((T2.Type)='', 'EMPLOYEE' ,
iif(T2.Type='Contractor',
'SUBCONTRACTOR',T2.Type)) AS Cost_Type2, T2.Team AS Cost_Type3, t2.CostCentre AS GroupCostCentre, iif( t3.[Project Code] = '998','Leave', iif( t3.[Portfolio] = 'OVERHEAD', 'Overhead', 'Productive')) AS Hrs_type, iif( t2.team in ('ADMIN SUPPORT','COMPANY MANAGEMENT','FACILITIES','FINANCE','HR','IT','LEGAL & EC','MARKETING','SUPPLY CHAIN'), 'Support Functions', 'Productive Functions') AS Function_type
FROM ((prep_act_time1 AS t1 LEFT JOIN Resources AS t2 ON t1.[Resource Code] = t2.[Resource Code]) LEFT JOIN 2019_Cost_rates_data AS t4 ON t1.[Resource Code] = t4.[Resource Code]) LEFT JOIN Ref_Project_Task AS t3 ON t1.ProjectCentreID = t3.Key;
This is the original query which works fine
SELECT '' AS [Nominal Code], datevalue(t1.Date) AS DayDate, month(t1.Date) AS [Month], '' AS [Header Ref], '' AS [Internal Ref], t2.Resource_ID & ' ' & T2.Name AS Supplier, year( t1.Date) AS [Year], t1.[Project Code] AS Project, t1.[Cost Centre Code] AS Task, t1.ProjectCentreID AS TaskKey, t1.ApprovalStatus AS [Detail Line], datevalue(t1.Date) AS Required, '_Staff' AS OrderNumber, datevalue(t1.Date) AS [Order Date], t2.Resource_ID AS [Entered by], '' AS [Line Number], iif(t3.Portfolio ='OVERHEAD', 0,
iif( DateValue(t1.Date) < datevalue('01/01/2019'), iif(t1.Price = 0, 0, 90),
iif(t2.Type = 'GRADUATE SECONDEE', 0,
iif( t2.team in ('QA AND H&S', 'SC&P-C&S','APPLIED TECH COMMERI') ,0,
switch(
DateValue(t1.Date) < datevalue('01/01/2020'), iif( t4.[User Sort 2] in ('MACHINE SHOP', 'PRODUCTION - HX MANU','SC&P-MANUF OPERATION','SC&P-MACHINISTS'), 65, 80),
DateValue(t1.Date) < datevalue('01/01/2021'), iif( t4.[User Sort 2] in ('MACHINE SHOP', 'PRODUCTION - HX MANU','SC&P-MANUF OPERATION','SC&P-MACHINISTS'), 65, t4.[Resource Price 1]),
DateValue(t1.Date) >= datevalue('01/01/2021'), iif( t2.Team in ('MACHINE SHOP', 'PRODUCTION - HX MANU','SC&P-MANUF OPERATION', 'SC&P-TECHNICAL','SC&P-MACHINISTS'), 68, 98)
)))))* t1.Quantity AS Net, t1.Quantity AS Hours, '' AS [Nominal Account Name], 'Labour' AS CostType1, iif((T2.Type)='', 'EMPLOYEE' ,
iif(T2.Type='Contractor',
'SUBCONTRACTOR',T2.Type)) AS Cost_Type2, T2.Team AS Cost_Type3, t2.CostCentre AS GroupCostCentre, iif( t3.[Project Code] = '998','Leave', iif( t3.[Portfolio] = 'OVERHEAD', 'Overhead', 'Productive')) AS Hrs_type, iif( t2.team in ('ADMIN SUPPORT','COMPANY MANAGEMENT','FACILITIES','FINANCE','HR','IT','LEGAL & EC','MARKETING','SUPPLY CHAIN'), 'Support Functions', 'Productive Functions') AS Function_type
FROM ((prep_act_time1 AS t1 LEFT JOIN Resources AS t2 ON t1.[Resource Code] = t2.[Resource Code]) LEFT JOIN 2019_Cost_rates_data AS t4 ON t1.[Resource Code] = t4.[Resource Code]) LEFT JOIN Ref_Project_Task AS t3 ON t1.ProjectCentreID = t3.Key;