Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a table like

SQL
Currencyid      C_Title
1               USD
2               INR
3               CAD
4               EUR
5               EGP

Select * from Currency Order by C_Title


Result comes this:
SQL
Currencyid      C_Title

3               CAD
5               EGP
4               EUR
2               INR
1               USD

but my requirement is :

SQL
Currencyid      C_Title

2               INR
3               CAD
5               EGP
4               EUR
1               USD
Posted
Updated 1-Oct-13 1:19am
v2
Comments
Thanks7872 1-Oct-13 7:20am    
What is the criteria for ordering like this?
abbaspirmoradi 1-Oct-13 7:22am    
what is your reason?why your requirement must sort like this?
Mubin M. Shaikh 1-Oct-13 7:27am    
First of all as above friends told , how do you sort like above?if you have done that then for first value/row you can use select top 1 * from tablename.
ZurdoDev 1-Oct-13 7:39am    
Why is your requirement that way? If you can answer that then you can answer how to sort it.

Try this code. Replace @Currency with Currency

SQL
Select 1 as displayorder,Currencyid,C_Title from @Currency where C_Title = 'INR'
union all
Select 2 as displayorder,Currencyid, C_Title from @Currency where C_Title <> 'INR' 
order by displayorder, C_Title
 
Share this answer
 
Comments
Member 9964247 2-Oct-13 6:42am    
its working. thank u ArunRajendra:)
ArunRajendra 3-Oct-13 2:28am    
Thank you. Please mark the answer as answered so that its will be useful for others. and if you feel like giving the ratting then rate with 1 being the lowest and 5 being the highest.
You can use a CASE WHEN in an ORDER BY clause if you don't have any "normal" order to your rows and need them sorted in a specific order:
SQL
SELECT CurencyId, C_Title FROM MyTable
ORDER BY
    ( CASE
       WHEN C_Title='INR' THEN 0
       WHEN C_Title='CAD' THEN 1
       WHEN C_Title='EGP' THEN 2
       WHEN C_Title='EUR' THEN 3
       WHEN C_Title='USD' THEN 4
       ELSE CurrencyId
      END )
 
Share this answer
 
 
Share this answer
 
you must do it with sort if possible or one bye one write and read
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900