I've got sorting blues...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Here's the table:

acct_id char(4)
age int
acct_bal currency
last_update_date date

I need a query that will present the records in this order:
Age
Acct_bal

Here's the kicker: I want the records that have been updated in the last 15
days (last_update_date) to be sorted LAST regardless of Age and Acct_bal
values. Can this be done in a query?
 
Scagnetti said:
Here's the table:

acct_id char(4)
age int
acct_bal currency
last_update_date date

I need a query that will present the records in this order:
Age
Acct_bal

Here's the kicker: I want the records that have been updated in the last 15
days (last_update_date) to be sorted LAST regardless of Age and Acct_bal
values. Can this be done in a query?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

That's really 2 queries ('cuz of 2 different sorts) so, probably a UNION
would do it.

Untested:

SELECT acct_id, age, acct_bal
FROM (
(SELECT acct_id, age, acct_bal
FROM table_name
WHERE last_update_date <= Date()-15
ORDER BY age, acct_bal) As B4

UNION ALL

(SELECT acct_id, age, acct_bal
FROM table_name
WHERE last_update_date > Date()-15
ORDER BY age, acct_bal) As Aft
) As T

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQubyz4echKqOuFEgEQLy2wCffLui52LHSYPRECYvqUXLrxkp49AAoL/W
NSegkHPoDAhxXfizG6nq7sxk
=x/0e
-----END PGP SIGNATURE-----
 
Scagnetti said:
Here's the table:

acct_id char(4)
age int
acct_bal currency
last_update_date date

I need a query that will present the records in this order:
Age
Acct_bal

Here's the kicker: I want the records that have been updated in the last 15
days (last_update_date) to be sorted LAST regardless of Age and Acct_bal
values. Can this be done in a query?


Try using this kind of ORDER BY clause:

IIf(Date() - last_update_date <= 15, 1, 0), Age, Acct_bal
 
Back
Top