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 2000 Forums
 SQL Server Development (2000)
 Changing the Order of ONE record

Author  Topic 

jesus4u
Posting Yak Master

204 Posts

Posted - 2003-01-02 : 10:59:26
From a SELECT statement, can I say SELECT 10 records BUT take the last record and put it on the TOP of the result?

example:
12345678910

change to:
10123456789

Thanks

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-01-02 : 11:30:04
If you are ordering by ID, you could try something like:

SELECT * FROM
(
SELECT A.*, CASE WHEN A.ID = (SELECT Max(ID) FROM Table) THEN -1 ELSE A.ID END AS Sort
FROM
Table A
)
ORDER BY Sort ASC

Add TOP's and criteria as necessary to the subqueries (be sure they are consistent).

Alter the -1 result as needed to make sure you sort the MAX() to the beginning.


- Jeff

Edited by - jsmith8858 on 01/02/2003 11:30:41
Go to Top of Page
   

- Advertisement -