Wednesday, March 28, 2012

Order by question, pls help

Hello,
I need to sort my data by location name, but the first record I need to
return is the one with location "Corporate" and then location name from A-Z.
How can I use order by to return "Corporate" records first and then return
"Atlanta", "Boston"...?
Thanks in advance!ORDER BY CASE LocationName WHEN 'Corporate' THEN 1 ELSE 2 END, LocationName;
"Jean" <Jean@.discussions.microsoft.com> wrote in message
news:072B9390-EFDB-4A9C-8D2B-91399F6AB0C8@.microsoft.com...
> Hello,
> I need to sort my data by location name, but the first record I need to
> return is the one with location "Corporate" and then location name from
> A-Z.
> How can I use order by to return "Corporate" records first and then return
> "Atlanta", "Boston"...?
> Thanks in advance!|||Try:
select
*
from
MyTable
order by
case when Location = 'Corporate' then 0 else 1 end
, Location
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada
.
"Jean" <Jean@.discussions.microsoft.com> wrote in message
news:072B9390-EFDB-4A9C-8D2B-91399F6AB0C8@.microsoft.com...
Hello,
I need to sort my data by location name, but the first record I need to
return is the one with location "Corporate" and then location name from A-Z.
How can I use order by to return "Corporate" records first and then return
"Atlanta", "Boston"...?
Thanks in advance!|||Tom / Aaron,
Thanks for your help! It works great!
Jean
"Jean" wrote:

> Hello,
> I need to sort my data by location name, but the first record I need to
> return is the one with location "Corporate" and then location name from A-
Z.
> How can I use order by to return "Corporate" records first and then return
> "Atlanta", "Boston"...?
> Thanks in advance!

No comments:

Post a Comment