Solved

How to set order by clause for this query.

Posted on 2013-01-19
2
230 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

9 Experts available now in Live!

Get 1:1 Help Now