Solved

How to set order by clause for this query.

Posted on 2013-01-19
2
231 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
2 Comments
 
LVL 142

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
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.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

911 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now