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.
| Author |
Topic |
|
rajendrarama
Starting Member
14 Posts |
Posted - 2011-10-01 : 12:00:29
|
| Hi,I have a table with column values as 'please select', 'b', 'a', 'c'.I want the query to perform the result set in the order 'please select''a''b''c'I tried the query:select columnname from tablename where columnname ='please select'union allselect columnname from tablename where columnname <>'please select' order by columnnameIt has not worked since order by applies for the whole and results in 'a''b''c''please select'which is not what i wanted. Can anyone help with the query.Thanks, |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-01 : 12:12:06
|
| [code]select columnname from tablenameorder by case when columnname ='please select' then 1 else 2 end asc, columnname asc[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
paultech
Yak Posting Veteran
79 Posts |
Posted - 2011-10-02 : 06:37:30
|
| hi ,you also can try the following code :select * from (select Top 1 columnname from tablename where columnname ='please select') as xxunion allselect * from (select Top 1 columnname from tablename where columnname <>'please select' order by columnname) as xxgood luckpaul Tech |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-02 : 07:40:05
|
quote: Originally posted by paultech hi ,you also can try the following code :select * from (select Top 1 columnname from tablename where columnname ='please select') as xxunion allselect * from (select Top 1 columnname from tablename where columnname <>'please select' order by columnname) as xxgood luckpaul Tech
why splitting it with union all if you can do it in same statement itself------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|