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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-04-12 : 09:00:51
|
| Brad writes "Is there a way i can order by specific entries? (not ordering in alphabetical order?)Example,field values:Subcat=========broadbandbroadbandbroadbandwirelesswirelesswirelessusbusbusbis there a way i can order wireless first broadband second and usb third all in a stored procedure?" |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2002-04-12 : 09:35:38
|
| You can use a CASE statement to evaluate the SubCat column and generate the sort value you want:SELECT SubCat FROM myTableORDER BY CASE SubCatWHEN 'broadband' THEN -2WHEN 'wireless' THEN -1WHEN 'usb' THEN 0ELSE 1 ENDYou can use any values you want; I like to use negative numbers for the pre-defined sort orders, then have the rest sorted with positive numbers. |
 |
|
|
setbasedisthetruepath
Used SQL Salesman
992 Posts |
Posted - 2002-04-12 : 10:37:38
|
| or make the sort order data driven by adding an (int) column to the subcat table, populating it with the rank of the particular description, and specifying it in your order by.setBasedIsTheTruepath<O> |
 |
|
|
|
|
|