Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 2 SQL Stms' results to appear one after the other

Author  Topic 

Gopher
Yak Posting Veteran

83 Posts

Posted - 2006-09-22 : 10:55:11
Hi All

I have a problem where I am making 2 select statements on the same table:

select * from SectorSalesByPrdGroup
where branch = '1100' and sectorcode <> 'Zt'
order by prodgrp,sectorcode


select * from SectorSalesByPrdGroup
where branch = '1100' and sectorcode = 'Zt'
order by prodgrp,sectorcode

I want the results of the second query with 'Zt' to appear at the bottom of the results. I tried using the Union syntax but it did not work.

Any ideas????

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-09-22 : 11:18:47
try this. the 2 query can be combine into 1.

select *
from SectorSalesByPrdGroup
where branch = '1100'
order by case when sectorcode <> 'Zt' then 0 else 1 end, prodgrp, sectorcode



KH

Go to Top of Page

Gopher
Yak Posting Veteran

83 Posts

Posted - 2006-09-22 : 11:42:21
Thanks worked perfectly!

quote:
Originally posted by khtan

try this. the 2 query can be combine into 1.

select *
from SectorSalesByPrdGroup
where branch = '1100'
order by case when sectorcode <> 'Zt' then 0 else 1 end, prodgrp, sectorcode



KH



Go to Top of Page
   

- Advertisement -