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,Custo mercode,Ja n,Feb ,Mar Apr,May,Jun,Jul,Aug,Oct,No v,Dec,Tota l
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,Custo
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much. This is exactly what I need.