Solved

How to set order by clause for this query.

Posted on 2013-01-19
2
234 Views
Last Modified: 2013-01-19
create table mstsubs (subjects varchar(200))
insert into mstsubs(subjects) values('aaan')
insert into mstsubs(subjects) values('baan')
insert into mstsubs(subjects) values('caan')

The output should be
select
ALL
aaan
baan
caan
I am using the following query but not working out.

select subjects
from(select 'Select' as subjects union select subjects from mstsubs
union select 'All' as subjects union select subjects from mstsubs)x
order by case
when subjects = 'Select' then 0
when subjects='ALL' THEN 1
END
0
Comment
Question by:searchsanjaysharma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 38796152
Please add
Else 2
to your case expression
0
 

Author Closing Comment

by:searchsanjaysharma
ID: 38796158
tx
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question