thebatfink
Well-known member
- Joined
- Mar 29, 2012
- Messages
- 47
- Programming Experience
- Beginner
Hi, having an absolute brick wall today and seemingly unable to work anything out alone :/
I want to perform a union query, and then group and order the results. I have taken care to make sure the same number of fields are present from both select queries and all the field names match etc, but I still can't seem to make it work. I'm having a hard time formatting a google search string that works to find examples.
Here is the bones of it.. but obviously I have some dodgy syntax as it doesn't like it!
What am I doing wrong? Thanks!
I want to perform a union query, and then group and order the results. I have taken care to make sure the same number of fields are present from both select queries and all the field names match etc, but I still can't seem to make it work. I'm having a hard time formatting a google search string that works to find examples.
Here is the bones of it.. but obviously I have some dodgy syntax as it doesn't like it!
VB.NET:
SELECT CONVERT(nvarchar(10), MyersTable.PlanWeek, 103) as [PlanWeek], IntIngredientTable.IngredientName, SUM(IntIngredientTable.Quantity) as [Quantity (KG)]
FROM IntIngredientTable
INNER JOIN MyersTable on IntIngredientTable.MyersID = MyersTable.MyersID
UNION ALL
SELECT CONVERT(nvarchar(10), RawDataTable.PlanWeek, 103) as [PlanWeek], IngredientTable.IngredientName, SUM(IngredientTable.Quantity) as [Quantity (KG)]
FROM IngredientTable
INNER JOIN RawDataTable on IngredientTable.RawDataID = RawDataTable.RawDataID
WHERE IngredientTable.Intermediate='No'
GROUP BY IngredientName, PlanWeek
ORDER BY CONVERT(DateTime, PlanWeek, 103)
What am I doing wrong? Thanks!