Hi, hope someone may be able to advise!
I am trying to join two queries into a pivot table
This pivot on one query works:
TRANSFORM Count(SampleTestedFor.TestedFor) AS TestedFor
SELECT IIf([SampleTestedFor].[Packed]=8,'','LCMS') AS TestGroup
FROM ((Samples_List INNER JOIN SampleTestedFor ON Samples_List.Sample_ID = SampleTestedFor.Sample_ID) LEFT JOIN Test_Methods ON SampleTestedFor.UniqueMethod_ID = Test_Methods.UniqueMethod_ID) INNER JOIN Orders ON Samples_List.Order_ID = Orders.Order_ID
WHERE (((Orders.Order_received)>='2021-02-01' And (Orders.Order_received)<='2022-07-27') AND ((Test_Methods.TestGroupCode)=8 Or (Test_Methods.TestGroupCode)=9))
GROUP BY SampleTestedFor.Packed
PIVOT Format([Order_received],'yyyy') & " " & Right('0' & Format([Order_received],'mm'),2);
However, adding a second does not "Syntax error (missing operator in query expression 'SampleTestedFor.Packed Union All ....."
TRANSFORM Count(SampleTestedFor.TestedFor) AS TestedFor
SELECT IIf([SampleTestedFor].[Packed]=8,'','LCMS') AS TestGroup
FROM ((Samples_List INNER JOIN SampleTestedFor ON Samples_List.Sample_ID = SampleTestedFor.Sample_ID) LEFT JOIN Test_Methods ON SampleTestedFor.UniqueMethod_ID = Test_Methods.UniqueMethod_ID) INNER JOIN Orders ON Samples_List.Order_ID = Orders.Order_ID
WHERE (((Orders.Order_received)>='2021-02-01' And (Orders.Order_received)<='2022-07-27') AND ((Test_Methods.TestGroupCode)=8 Or (Test_Methods.TestGroupCode)=9))
GROUP BY SampleTestedFor.Packed
Union All
SELECT IIf([SampleTestedFor].[Packed]=8,'','ELISA') AS TestGroup
FROM ((Samples_List INNER JOIN SampleTestedFor ON Samples_List.Sample_ID = SampleTestedFor.Sample_ID) LEFT JOIN Test_Methods ON SampleTestedFor.UniqueMethod_ID = Test_Methods.UniqueMethod_ID) INNER JOIN Orders ON Samples_List.Order_ID = Orders.Order_ID
WHERE (((Orders.Order_received)>='2021-02-01' And (Orders.Order_received)<='2022-07-27') AND ((Test_Methods.TestGroupCode)=1 Or (Test_Methods.TestGroupCode)=2))
GROUP BY SampleTestedFor.Packed
PIVOT Format([Order_received],'yyyy') & " " & Right('0' & Format([Order_received],'mm'),2);
I am not able to ascertain what I am doing wrong, i.e., is there indeed a syntax error or is the code completely wrong.
Thanks
Harris
I am trying to join two queries into a pivot table
This pivot on one query works:
TRANSFORM Count(SampleTestedFor.TestedFor) AS TestedFor
SELECT IIf([SampleTestedFor].[Packed]=8,'','LCMS') AS TestGroup
FROM ((Samples_List INNER JOIN SampleTestedFor ON Samples_List.Sample_ID = SampleTestedFor.Sample_ID) LEFT JOIN Test_Methods ON SampleTestedFor.UniqueMethod_ID = Test_Methods.UniqueMethod_ID) INNER JOIN Orders ON Samples_List.Order_ID = Orders.Order_ID
WHERE (((Orders.Order_received)>='2021-02-01' And (Orders.Order_received)<='2022-07-27') AND ((Test_Methods.TestGroupCode)=8 Or (Test_Methods.TestGroupCode)=9))
GROUP BY SampleTestedFor.Packed
PIVOT Format([Order_received],'yyyy') & " " & Right('0' & Format([Order_received],'mm'),2);
However, adding a second does not "Syntax error (missing operator in query expression 'SampleTestedFor.Packed Union All ....."
TRANSFORM Count(SampleTestedFor.TestedFor) AS TestedFor
SELECT IIf([SampleTestedFor].[Packed]=8,'','LCMS') AS TestGroup
FROM ((Samples_List INNER JOIN SampleTestedFor ON Samples_List.Sample_ID = SampleTestedFor.Sample_ID) LEFT JOIN Test_Methods ON SampleTestedFor.UniqueMethod_ID = Test_Methods.UniqueMethod_ID) INNER JOIN Orders ON Samples_List.Order_ID = Orders.Order_ID
WHERE (((Orders.Order_received)>='2021-02-01' And (Orders.Order_received)<='2022-07-27') AND ((Test_Methods.TestGroupCode)=8 Or (Test_Methods.TestGroupCode)=9))
GROUP BY SampleTestedFor.Packed
Union All
SELECT IIf([SampleTestedFor].[Packed]=8,'','ELISA') AS TestGroup
FROM ((Samples_List INNER JOIN SampleTestedFor ON Samples_List.Sample_ID = SampleTestedFor.Sample_ID) LEFT JOIN Test_Methods ON SampleTestedFor.UniqueMethod_ID = Test_Methods.UniqueMethod_ID) INNER JOIN Orders ON Samples_List.Order_ID = Orders.Order_ID
WHERE (((Orders.Order_received)>='2021-02-01' And (Orders.Order_received)<='2022-07-27') AND ((Test_Methods.TestGroupCode)=1 Or (Test_Methods.TestGroupCode)=2))
GROUP BY SampleTestedFor.Packed
PIVOT Format([Order_received],'yyyy') & " " & Right('0' & Format([Order_received],'mm'),2);
I am not able to ascertain what I am doing wrong, i.e., is there indeed a syntax error or is the code completely wrong.
Thanks
Harris