I am trying to do a report that shows the same job done on a unit within 6 months of the previous job. Here's my SQL:
SELECT b.Unit, b.Job, b.WO, b.[Unit-Job], b.[Unit-Job-WO], b.RepairDate, b!RepairDate-[Repairs]![RepairDate] AS [Delta in Days], [Repairs].WO AS [Previous WO], [Repairs].RepairDate AS [Previous WO Repair Date]
FROM [Repairs] AS b INNER JOIN [Repairs] ON b.[Unit-Job] = [Repairs].[Unit-Job]
WHERE (((b.RepairDate)>[Repairs].[RepairDate]) AND ((![RepairDate]-[Repairs]![RepairDate])<=180))
ORDER BY b.[Unit-Job-WO];
Its giving me the Delta in Days of all the previous jobs not just the most recent job...so if there was four jobs with repair dates of 2/1/06(WO #1), 5/1/06(WO #2) and 7/1/06 (WO #3) and 10/1/06 (WO #4)...for WO #2 the report returns a Delta of 90 days, for WO #3 it returns a Delta of 150 and 60 days (only want 60days) and for WO #4 it returns a Delta of 150 and 90 days (only want 90days..so the report is returning more information than I need.
Any help you can give me would be greatly appreciated.
SELECT b.Unit, b.Job, b.WO, b.[Unit-Job], b.[Unit-Job-WO], b.RepairDate, b!RepairDate-[Repairs]![RepairDate] AS [Delta in Days], [Repairs].WO AS [Previous WO], [Repairs].RepairDate AS [Previous WO Repair Date]
FROM [Repairs] AS b INNER JOIN [Repairs] ON b.[Unit-Job] = [Repairs].[Unit-Job]
WHERE (((b.RepairDate)>[Repairs].[RepairDate]) AND ((![RepairDate]-[Repairs]![RepairDate])<=180))
ORDER BY b.[Unit-Job-WO];
Its giving me the Delta in Days of all the previous jobs not just the most recent job...so if there was four jobs with repair dates of 2/1/06(WO #1), 5/1/06(WO #2) and 7/1/06 (WO #3) and 10/1/06 (WO #4)...for WO #2 the report returns a Delta of 90 days, for WO #3 it returns a Delta of 150 and 60 days (only want 60days) and for WO #4 it returns a Delta of 150 and 90 days (only want 90days..so the report is returning more information than I need.
Any help you can give me would be greatly appreciated.