Question : Union All Query for Sub Report Order By

I have the following Union All query which is used as the record source for a sub report.
SELECT *
FROM (SELECT [Tracking Number], "Address Correction" as [Service Name], [Address_Corr_Rate] as Charge FROM Invoice UNION ALL
SELECT [Tracking Number], "Rate" as [Service Name], [Base Rate] as Charge FROM Invoice UNION ALL
SELECT [Tracking Number], "Additional Handling" as [Service Name], [Exc_Packaging_Rate] as Charge FROM Invoice UNION ALL
SELECT  [Tracking Number], "Fuel Surcharge" as [Service Name], [Fuel Billed] as Charge FROM Invoice UNION ALL
SELECT  [Tracking Number], "Total" as [Service Name], [SubTotal] as Charge FROM Invoice UNION ALL
SELECT [Tracking Number], "Oversize Charge" as [Service Name], [Oversize_Charge] as Charge FROM Invoice)  AS T1
WHERE (((T1.Charge)<>0))
ORDER BY T1.[Tracking Number], T1.[Service Name];


The Sub Report expands to accept all the middle charges.  The problem is the order of the results in the sub report. I am getting as follows,

Service Name            |     Charge
Additional Handling          10.00
Address Correction           10.00
Fuel Surcharge                 1.50
Oversize Charge               12.00
Rate                                25.00
Total                                58.50

How do I get it in this order?
Service Name            |     Charge
Rate                                 25.00   (Allways first)
Additional Handling            10.00
Address Correction            10.00
Oversize Charge                12.00
Fuel Surcharge                  1.50    (Allways Second to Last)
Total                                 58.50  (Allways Last)


Answer : Union All Query for Sub Report Order By

Change the SQL to:

SELECT *
FROM (SELECT 3 AS SortOrder, [Tracking Number], "Address Correction" as [Service Name], [Address_Corr_Rate] as Charge FROM Invoice UNION ALL
SELECT 1 AS SortOrder, [Tracking Number], "Rate" as [Service Name], [Base Rate] as Charge FROM Invoice UNION ALL
SELECT 2 AS SortOrder, [Tracking Number], "Additional Handling" as [Service Name], [Exc_Packaging_Rate] as Charge FROM Invoice UNION ALL
SELECT  5 AS SortOrder, [Tracking Number], "Fuel Surcharge" as [Service Name], [Fuel Billed] as Charge FROM Invoice UNION ALL
SELECT  6 AS SortOrder, [Tracking Number], "Total" as [Service Name], [SubTotal] as Charge FROM Invoice UNION ALL
SELECT 4 AS SortOrder, [Tracking Number], "Oversize Charge" as [Service Name], [Oversize_Charge] as Charge FROM Invoice)  AS T1
WHERE (((T1.Charge)<>0))
ORDER BY T1.[Tracking Number], T1.[SortOrder];
Random Solutions  
 
programming4us programming4us