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 2005 Forums
 Transact-SQL (2005)
 Order By - but put one at the end. A Union??

Author  Topic 

Zath
Constraint Violating Yak Guru

298 Posts

Posted - 2008-08-26 : 14:00:53
I want this list to be in order a certain way.
But I want just one in the list to be at the end.

Need a little input here on this one....

select Name from Event
where Code <> 'P'
--order by Name
UNION
select Name from Event
where Code = 'P'

It doesn't like the order by

I just want the ordered list with out one to put at the end.

Thanks,

Zath

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2008-08-26 : 14:07:01
[code]
select
[Name]
from Event
order by Case Code WHEN 'P' THEN 1 Else 0 END asc, [name]
[/code]

"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page

Zath
Constraint Violating Yak Guru

298 Posts

Posted - 2008-08-26 : 14:13:43
I simplified the sql for my post.

I applied your suggestion and it's not working right...

select EventGroupCode, EventGroupName, IsNull(WebDescription, '') WebDescription, SmartFormID
from EventGroup
order by Case EventGroupName WHEN 'ICP' THEN 1 Else 0 END asc, EventGroupName


I even tried

select EventGroupCode, EventGroupName, IsNull(WebDescription, '') WebDescription, SmartFormID
from EventGroup
order by Case EventGroupName WHEN 'ICP' THEN 1 Else 0 END asc, EventGroupName, EventGroupName, IsNull(WebDescription, '') WebDescription, SmartFormID

But it didn't like WebDescription

Suggestions?

Thanks again,

Zath

Go to Top of Page

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2008-08-26 : 14:24:01
[code]
select
EventGroupCode,
EventGroupName,
IsNull(WebDescription, '') as WebDescription,
SmartFormID
from EventGroup
order by Case EventGroupCode WHEN 'ICP' THEN 1 Else 0 END asc, EventGroupName
[/code]

"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page

Zath
Constraint Violating Yak Guru

298 Posts

Posted - 2008-08-26 : 14:30:25
Thanks. Had a field wrong.

Zath
Go to Top of Page
   

- Advertisement -