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 2000 Forums
 SQL Server Development (2000)
 Reverse select statement

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-03-23 : 14:26:06
Sanjeev writes "My Question is:

I have table like this

EmpId        Location
------------------------
56 E-commerce
2 Soft-ware
23 Hard-ware
5 Communication
-------------------------------


Now i need this result :

EmpId        Location
------------------------
5 Communication
23 Hard-ware
2 Soft-ware
56 E-commerce
----------------------------

Can anybody tell me how to get it???
Thanks in Advanced."

tripurariyadav
Starting Member

1 Post

Posted - 2011-04-20 : 05:12:42
--create table yourtable (EmpId int, Location varchar(50))
--insert into yourtable values (56,'E-commerce')
--insert into yourtable values (2,'Soft-ware')
--insert into yourtable values (23,'Hard-ware')
--insert into yourtable values (5,'Communication')


-- SELECT EmpId, Location FROM yourtable
/*
56 E-commerce
2 Soft-ware
23 Hard-ware
5 Communication

*/

SELECT EmpId, Location FROM yourtable
ORDER BY
CASE WHEN Location Like 'E-%' THEN 1 ELSE 0 END, Location



--After Sort:
/*
5 Communication
23 Hard-ware
2 Soft-ware
56 E-commerce

*/



Thank Regards,
Tripurari Yadav
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2011-04-20 : 05:26:12
Please note: 10 year old thread.

--
Gail Shaw
SQL Server MVP
Go to Top of Page
   

- Advertisement -