Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ORDER BY 1

Status
Not open for further replies.

TomBarrand

Programmer
Joined
Aug 9, 2000
Messages
162
Location
GB
I am currently using the following SQL statement to populate a drop doewn box. I need 'GBP', 'USD' to be at the top of the list then the remainding options to appear in ascending order. How do I do this

Select Curr_ISO_Code
FROM Currency
WHERE Curr_Status = 'A'

Thanks
 
This will work if you then just ignore the column 'type' in your drop down box.

Select Curr_ISO_Code,1 as type
from Currency
where Curr_Status = 'A' and Curr_ISO_Code = 'GBP'
union
Select Curr_ISO_Code,2 as type
from Currency
where Curr_Status = 'A' and Curr_ISO_Code = 'USD'
union
Select Curr_ISO_Code,3 as type
from Currency
where Curr_Status = 'A' and Curr_ISO_Code not in ('GBP','USD')
order by type


Rick.


 

Another solution is to use a CASE statement in the ORDER BY clause.

Select Curr_ISO_Code
FROM Currency
WHERE Curr_Status = 'A'
ORDER BY
Case Curr_ISO_Code
When 'GBP' Then 1
When 'USD' Then 2
Else 3 End,
Curr_ISO_Code Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top