Complex query sort (1 Viewer)

DocNice

Registered User.
Local time
Yesterday, 19:33
Joined
Oct 6, 2004
Messages
76
I need to sort my query in a rather complicated way, and haven't been able to get the examples I've found on here to work.

I have the following fields
[Category]
[Name]
[Page]

Here is what I need.
Where [Category] = "Table of Contents"
Sort by [Name], Then by [Page] Descending
Else
Sort by [Name], Then by [Page] Ascending

All records will be queried at the same time, so "Table of Contents" categories will be included in the same query as other records, but need a different sort order. I know this is stupid, but leave it to government to impose some nonsensical rule on you.

Is there a way to do this?
Thanks,
Doc
 

mresann

Registered User.
Local time
Yesterday, 19:33
Joined
Jan 11, 2005
Messages
357
Doc, can you zip a table with the data already in place? Or, is this the structure you have now?

Catetgory Name Page
Table of Contents John 17
Table of Contents Steve 455
Table of Contents Steve 388
Table of Contents Steve 124
Table of Contents Steve 67
Table of Contents Steve 52
Table of Contents Steve 478
Table of Contents John 7655
Table of Contents John 5
Table of Contents Steve 48
Table of Contents Steve 76
Table of Contents Steve 4587
Table of Contents John 64
Table of Contents John 46
Table of Contents John 89
Table of Contents John 4788
Table of Contents Steve 654
Table of Contents Steve 60
Table of Contents Steve 8465
Table of Contents John 56
Table of Contents John 29
Table of Contents Steve 84
Table of Contents Steve 3
Table of Contents Steve 4
Table of Contents Steve 6
Table of Contents Steve 7
Table of Contents Steve 8
 

DocNice

Registered User.
Local time
Yesterday, 19:33
Joined
Oct 6, 2004
Messages
76
It should look like this. Note the different sort order on the Table of Contents:

Category, Name, Page
Rates, AA, 1
Rates, AA, 2
Rates, AA, 3
Rates, BB, 1
Rates, BB, 2
Rates, BB, 3
Statements, First, 1
Statements, First, 2
Statements, First, 3
Statements, Second, 1
Statements, Second, 2
Statements, Second, 3
Table of Contents, Rates, 3
Table of Contents, Rates, 2
Table of Contents, Rates, 1
Table of Contents, Statements, 3
Table of Contents, Statements, 2
Table of Contents, Statements, 1
 

DALeffler

Registered Perpetrator
Local time
Yesterday, 20:33
Joined
Dec 5, 2000
Messages
263
Why not include a calculated field in the query and sort (ascending) by that calculated field?

Iif([tblMyTable].[fldName] <> "Table of Contents", [tlbMyTable].[fldPage], 100000 - [tblMyTable].[fldPage])

or something like that...

hth,
 

john471

Registered User.
Local time
Today, 12:33
Joined
Sep 10, 2004
Messages
392
To invert the sort order, could you multiply the Page by -1 when desireable???

SELECT tblYourTableName.fldCategory, tblYourTableName.fldName, tblYourTableName.fldPage
FROM tblYourTableName
ORDER BY tblYourTableName.fldCategory, tblYourTableName.fldName, IIf([fldCategory]<>"Table of Contents",[fldPage],-1*[fldPage]);
 

Users who are viewing this thread

Top Bottom