Calculating number of days between dates for records in the same t

D

Dan

I have built a query with a sub-query in it that I thought would calculate
the days between the dates on each record for a given Well# but I am not able
to make it work. Here is the query:

SELECT [Base Wells].[WELL#], [Base Wells].[WELL NAME], [All Daily Production
Data].[DATE-TIME], [All Daily Production Data].STATUS, [All Daily Production
Data].STCODE, [All Daily Production Data].[DATE-TIME]-(SELECT Max([All Daily
Production Data].[DATE-TIME]) FROM [All Daily Production Data] As Dup WHERE
[Base Wells].[Well#] = Dup.[Well#] AND Dup.[DATE-TIME] < [All Daily
Production Data].[DATE-TIME]) AS NumDays
FROM [Base Wells] LEFT JOIN [All Daily Production Data] ON [Base
Wells].[WELL#]=[All Daily Production Data].[WELL#]
WHERE ((([All Daily Production Data].STATUS)="P" Or ([All Daily Production
Data].STATUS)="N") AND (([Base Wells].CLASS)="W"))
ORDER BY [Base Wells].[WELL NAME], [All Daily Production Data].[DATE-TIME];

I also want the last record for a given Well# to show the number of days
between the last record date and the current date. I haven't dealt with that
challenge in this query yet.

When I run the query as it is, Numdays is returning 0. Apparently I am
subtractng the same date rather than the previous date.

Any ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top