Hi
Firstly a bit of background into the madness of my table. I had a sharepoint site linked to an access database for reporting. This SP site created workflows and tracked statuses, however for just over a day our SP server got full, so the new list items for tracking couldnt be created. As a backup plan, i ran an append query to track what the status was twice a day. The workflows are now ok, so need to condense my results.
For example, i have, the following for an ID of 1
Query4Defect_IDDefect StatusBU_DATE1327/02/20141328/02/20141303/03/20141303/03/20141804/03/20141805/03/20141706/03/20141710/03/20141711/03/20141713/03/20141713/03/2014
So defect 1, goes from status 3 to 8 then to 7.
I have the following to work out my table structure so far, the issue is getting the previous status.
SELECT MAIN.Defect_ID, MAIN.[Defect Status], Min(MAIN.BU_DATE) AS MinOfBU_DATE, (select top 1 t1.[defect status] from tbl_status_phase_change as t1 where t1.defect_id=main.defect_ID and t1.bu_date<(select min(t2.BU_date) from tbl_status_phase_change as t2 where t2.defect_Id=main.defect_ID and t2.[defect status]=main.[defect status]) order by t1.BU_date DESC) AS STATUS_FROM
FROM tbl_Status_Phase_Change AS MAIN
GROUP BY MAIN.Defect_ID, MAIN.[Defect Status]
HAVING (((MAIN.Defect_ID) Is Not Null))
ORDER BY MAIN.Defect_ID, Min(MAIN.BU_DATE);
However i get the error At most one record can be returned from this query, however, when i sort ascending its fine.
Many thanks,
Firstly a bit of background into the madness of my table. I had a sharepoint site linked to an access database for reporting. This SP site created workflows and tracked statuses, however for just over a day our SP server got full, so the new list items for tracking couldnt be created. As a backup plan, i ran an append query to track what the status was twice a day. The workflows are now ok, so need to condense my results.
For example, i have, the following for an ID of 1
Query4Defect_IDDefect StatusBU_DATE1327/02/20141328/02/20141303/03/20141303/03/20141804/03/20141805/03/20141706/03/20141710/03/20141711/03/20141713/03/20141713/03/2014
So defect 1, goes from status 3 to 8 then to 7.
I have the following to work out my table structure so far, the issue is getting the previous status.
SELECT MAIN.Defect_ID, MAIN.[Defect Status], Min(MAIN.BU_DATE) AS MinOfBU_DATE, (select top 1 t1.[defect status] from tbl_status_phase_change as t1 where t1.defect_id=main.defect_ID and t1.bu_date<(select min(t2.BU_date) from tbl_status_phase_change as t2 where t2.defect_Id=main.defect_ID and t2.[defect status]=main.[defect status]) order by t1.BU_date DESC) AS STATUS_FROM
FROM tbl_Status_Phase_Change AS MAIN
GROUP BY MAIN.Defect_ID, MAIN.[Defect Status]
HAVING (((MAIN.Defect_ID) Is Not Null))
ORDER BY MAIN.Defect_ID, Min(MAIN.BU_DATE);
However i get the error At most one record can be returned from this query, however, when i sort ascending its fine.
Many thanks,