0

I have the following table :

     tCustomerOrder
     -IdOrder
     -IdCustomer
     -OrderDate

I want a query to get a table with :

     -Idcustomer
     -LastOrder_date
     -LastOrder_Id
     -LastOrder_period   ''ie elasped time between the two last orders
     -NextOrder_Date     ''estimated date egal to LastOrder_date + LastOrder_period

I success to have LastOrder_Date (using MaxDom function to calculate a new fied) but when I use DiffDate it return en error.

     LastOrder_Date: MaxDom("OrderDate";""tCustomerOrder"";"[IdCustomer]=" [IdCustomer] & " AND [IdOrder]<>" & [IdOrder] & " AND  [OrderDate] < " & [OrderDate])

     DiffDate("\d";[tCustomerOrder];[LastOrderDate])

Must I have to use aggregate query? How do it work? Thanks a lot for your support.

Krish
  • 5,917
  • 2
  • 14
  • 35

3 Answers3

0

Use DateDiff function instead of DiffDate

Sergey S.
  • 6,296
  • 1
  • 14
  • 29
0

You calculate LastOrder_Date, but then you try to use [LastOrderDate]
(missing _ in name)

iDevlop
  • 24,841
  • 11
  • 90
  • 149
0

I found the answer thanks to MS Access SQL: Aggregating on Min Value but retrieving other fields

Here is the solution :

SELECT a.IdClient, a.LivraisonDateMax, m.IdCommande, 
m.NextLivraisonDelay, m.NextLivraisonDate
FROM 
(
   (
    SELECT IdClient, 
    Max(LivraisonDate) AS LivraisonDateMax 
    FROM qryBILANCommandeClient_All GROUP BY IdClient)  
    AS a INNER JOIN qryBILANCommandeClient_All AS m 
    ON (a.LivraisonDateMax = m.LivraisonDate) AND (a.IdClient = m.IdClient
    )
) 
INNER JOIN tClient_General ON a.IdClient = tClient_General.IdClient
ORDER BY tClient_General.DesignationCourte;