Avatar of jagr12
jagr12
 asked on

SQL - order result set when using union

When using union all, how can I order result set of how it gets displayed?  For example

Right now it returned

Descripton    SalesType        Customercode  Jan      Feb       Mar       Apr      May      Jun      Jul      Aug      Oct      Nov      Dec      Total
Sale            Direct             1             $          $      $
Manager            Resell             1             $          $      $
Inter            Extr             1             $          $      $
Exter            EU             1             $          $      $

I want to return like or any order of result set

Descripton    SalesType        Customercode  Jan      Feb       Mar       Apr      May      Jun      Jul      Aug      Oct      Nov      Dec      Total


Inter            Extr             1             $          $      $
Exter            EU             1             $          $      $
Manager            Resell             1             $          $      $
Sale            Direct             1             $          $      $


Table sample

column names

Descripton    SalesType        Customercode  Jan      Feb       Mar       Apr      May      Jun      Jul      Aug      Oct      Nov      Dec      Total


select *from
(
select * from #temp_table1
union all
select * from #temp_table2
union all
select * from #temp_table3
union all
select * from #temp_table4


a group by Descripton,SalesType,Customercode,Jan,Feb ,Mar Apr,May,Jun,Jul,Aug,Oct,Nov,Dec,Total
Microsoft SQL Server 2008Microsoft SQL ServerMicrosoft SQL Server 2005ASP.NET

Avatar of undefined
Last Comment
jagr12

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Jim Horn

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
jagr12

ASKER
Jim,
Thank you very much. This is exactly what I need.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck