Sorting in Union Select Query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to get this query which is sent to a report to sort by
[LeadDate]. I think I need to use ORDER BY but can't seem to get it to work.
Can anybody help?
thanks, Les.

SELECT
[Branch],[LeadDate],[CustomerName],[Rep],[ContractPrice],[PaymentMethod],[LeadSource],[Canvasser],[Units],[Product],[WeekNumber],[Year]
FROM [qryBentonOrders for Business Sheet]

UNION SELECT
[Branch],[LeadDate],[CustomerName],[Rep],[ContractPrice],[PaymentMethod],[LeadSource],[Canvasser],[Units],[Product],[WeekNumber],[Year]
FROM [tblOtherBranchSales]
WHERE [Year]=[Enter Other Branches Year] AND [WeekNumber]=[Enter Other
Branches Week Number];
 
LesLdh said:
I am trying to get this query which is sent to a report to sort by
[LeadDate]. I think I need to use ORDER BY but can't seem to get it
to work. Can anybody help?
thanks, Les.

SELECT
[Branch],[LeadDate],[CustomerName],[Rep],[ContractPrice],[PaymentMethod],[LeadSource],[Canvasser],[Units],[Product],[WeekNumber],[Year]
FROM [qryBentonOrders for Business Sheet]

UNION SELECT
[Branch],[LeadDate],[CustomerName],[Rep],[ContractPrice],[PaymentMethod],[LeadSource],[Canvasser],[Units],[Product],[WeekNumber],[Year]
FROM [tblOtherBranchSales]
WHERE [Year]=[Enter Other Branches Year] AND [WeekNumber]=[Enter Other
Branches Week Number];

If you are using the query for an Access report then set the sort order in the
report. It will ignore any sorting in the query anyway.

Otherwise yes, you need to add...

ORDER BY [LeadDate]

....at the bottom of the statement before the semi-colon.
 
Many thanks Rick, I knew the answer would be obvious when I saw it.

Rick Brandt said:
LesLdh said:
I am trying to get this query which is sent to a report to sort by
[LeadDate]. I think I need to use ORDER BY but can't seem to get it
to work. Can anybody help?
thanks, Les.

SELECT
[Branch],[LeadDate],[CustomerName],[Rep],[ContractPrice],[PaymentMethod],[LeadSource],[Canvasser],[Units],[Product],[WeekNumber],[Year]
FROM [qryBentonOrders for Business Sheet]

UNION SELECT
[Branch],[LeadDate],[CustomerName],[Rep],[ContractPrice],[PaymentMethod],[LeadSource],[Canvasser],[Units],[Product],[WeekNumber],[Year]
FROM [tblOtherBranchSales]
WHERE [Year]=[Enter Other Branches Year] AND [WeekNumber]=[Enter Other
Branches Week Number];

If you are using the query for an Access report then set the sort order in the
report. It will ignore any sorting in the query anyway.

Otherwise yes, you need to add...

ORDER BY [LeadDate]

....at the bottom of the statement before the semi-colon.
 
Back
Top