Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-Server-2008
Hi Friends,
 
I have a Currency table with records as follows :
 
ID Name
1 INR
2 USD
3 SGD
4 EURO
. .
. .
 
When I fire a query like, select * from Currecny, I get the recordset as shown.
 
But I want to get " SGD " as my first record, then all remaining records.
 
How can I get this?
 
Any help appreciated.
 
Thanks,
Lok.
Posted 22-Dec-11 18:22pm
Edited 22-Dec-11 19:47pm
RaisKazi32.9K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

select * from currency
order by
case name
when 'SGD' then 1
else 2
end
  Permalink  
Comments
Amir Mahfoozi at 23-Dec-11 4:36am
   
+5 Another good solution.
Scubapro at 23-Dec-11 4:38am
   
Tnx!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Amir's answer is enough but here alternative solution
Add an another column in your table(Ex. Default or DisplayOrder), see below table.
ID Name IsDefault
-----------------
1 INR   N
2 USD   N
3 SGD   Y
4 EURO  N
Use the Below Query
SELECT * FROM [Table] ORDER BY SGD DESC
ID Name DisplayOrder
-----------------
1 INR   2
2 USD   3
3 SGD   1
4 EURO  4
SELECT * FROM [Table] ORDER BY DisplayOrder
  Permalink  
Comments
Amir Mahfoozi at 23-Dec-11 1:05am
   
+5 Yes, I always use display order in my own projects :)
rks0191@gmail.com at 15-Oct-13 5:22am
   
nice one :)
RaviRanjankr at 23-Dec-11 1:36am
   
5+
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try this :
select * from currency where id=3
union all 
select * from color where id<>3
  Permalink  
Comments
thatraja at 23-Dec-11 1:02am
   
5!
RaviRanjankr at 23-Dec-11 1:36am
   
My 5+
LokeshZende at 23-Dec-11 3:11am
   
Thanks Amir... :)
Amir Mahfoozi at 23-Dec-11 4:27am
   
You're welcome :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 CPallini 355
1 BillWoodruff 334
2 George Jonsson 279
3 Sergey Alexandrovich Kryukov 243
4 Gihan Liyanage 225
0 OriginalGriff 5,050
1 CPallini 4,225
2 Sergey Alexandrovich Kryukov 3,639
3 George Jonsson 2,911
4 Gihan Liyanage 2,386


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 23 Dec 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100