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 2005 Forums
 Transact-SQL (2005)
 ORDER BY problem

Author  Topic 

ramoneguru
Yak Posting Veteran

69 Posts

Posted - 2007-03-02 : 20:20:00
OK, I have the following list of numbers/names:

OptionCode Name
OptionCode=101 'ABE Beginning Literacy'
OptionCode=102 'ABE Beginning Education'
OptionCode=103 'ABE Intermediate Low'
OptionCode=104 'ABE Intermediate High'
OptionCode=105 'ASE Low'
OptionCode=106 'ASE High'
OptionCode=108 'ESL Beginning Literacy'
OptionCode=121 'ESL Low Beginning'
OptionCode=122 'ESL High Beginning'
OptionCode=110 'ESL Intermediate Low'
OptionCode=111 'ESL Intermediate High'
OptionCode=112 'ESL Advanced'

I need them to appear in the order above, but I can't seem to formulate an ORDER BY clause that will work. ORDER BY OptionCode and ORDER BY Name do not work. Any ideas?
--Nick

ramoneguru
Yak Posting Veteran

69 Posts

Posted - 2007-03-02 : 20:58:03
Seemed to work, then just INNER JOIN this table with the results....

CREATE TABLE #SortTable
(
SortOrder INT,

OptionCode INT,

SortName VARCHAR (150)

)

INSERT INTO #SortTable
SELECT '1', '101', 'ABE Beginning Literacy'
UNION ALL
SELECT '2', '102', 'ABE Beginning Education'
UNION ALL
SELECT '3', '103', 'ABE Intermediate Low'
UNION ALL
SELECT '4', '104', 'ABE Intermediate High'
UNION ALL
SELECT '5', '105', 'ASE Low'
UNION ALL
SELECT '6', '106', 'ASE High'
UNION ALL
SELECT '7', '108', 'ESL Beginning Literacy'
UNION ALL
SELECT '8', '121', 'ESL Low Beginning'
UNION ALL
SELECT '9', '122', 'ESL High Beginning'
UNION ALL
SELECT '10', '110', 'ESL Intermediate Low'
UNION ALL
SELECT '11', '111', 'ESL Intermediate High'
UNION ALL
SELECT '12', '112', 'ESL Advanced'


A better solution out there maybe??
--Nick
Go to Top of Page
   

- Advertisement -