Adam said:
Set rs2 = cn.execute("select LAST(invoice_date) from invoice where
invoice_registration='0003' and invoice_member_id=" & CInt(rs(0)) & "
Order By invoice_date asc")
You tried to execute a query that does not include the specified
expression 'invoice_date' as part of an aggregate function.
/connect/admin/reminder/reminder.asp, line 14
Could someone be kind enough to give me a resolution to the problem
above. How do i accomplish this using JET SQL.
You are asking the query engine to do two different things: aggregate and
sort. What is the point of having an Order By clause on a query that will
return a single record?
LAST(invoice_date) will return the invoice_date contained in the last record
of the set of records that meet the requirements in the WHERE clause. This
value will NOT be contained in a field called invoice_date unless you
explicitly tell it to do so using a column alias. With Jet, the name of the
column returned by an expression will be given a default name like Expr001,
which you would see if you tested the query using the Access Query Builder
(you ARE testing the query before attempting to run it from ASP aren't you?)
The Order By clause can refer to a column not mentioned in your SELECT list.
However, when it does, a temporary work table is created that includes the
missing column. Normally, this works fine. In the case where you've used an
aggregate function, however, you cannot have both a column and an aggregate
function in the SELECT list unless the column is contained in a GROUP BY
clause, which your query lacks.
In your case, you need to ask what you are really after: it looks like you
simply want the value of the largest (latest) invoice_date in the set of
records meeting your criteria. This can be done using the MAX function:
SELECT MAX(invoice_date) FROM ....
(no ORDER BY clause needed)
Bob Barrows