I have a table which has a column of dates which I want to find the difference between. I have been able to find off your site an answer that gets me the difference between two dates, but can't find anything that would give me the difference between several records per customer.
My data looks as below:
Customer Pstng_Date
Henry 05\01\2014
Henry 10\01\2014
Henry 15\01/2014
Williams 07\01/2014
Williams 15\01\2014
I have been using the below code which will calculate the Williams example, but can't get it work so that it calculates all the Henry ones. What I want to see is:
Customer Pstng_Date Days_Between
Henry 05\01\2014 0
Henry 10\01\2014 5
Henry 15\01/2014 5
Williams 07\01/2014 0
Williams 15\01\2014 8
I have been using the below code to calculate the difference between two records only.
SELECT AllDays.ID, AllDays.Customer, AllDays.Pstng_Date, AllDays.NextDate, DateDiff("d",[Pstng_Date],[NextDate]) AS Days
FROM (SELECT ID, Customer, Pstng_Date,
( SELECT Min(Pstng_Date)
FROM SAPData T2
WHERE T2.Pstng_Date > T1.Pstng_Date
) AS NextDate
FROM SAPData T1
) AS AllDays;