I have two tables: Maint_history_T and Parts_T
I want to display all the parts in the parts table and a field called next_maint in Maint_history_T only if a field called status = 'Pending' in the Maint_history_T otherwise I want to leave the next_maint field blank in the recordset.
I tried something like this:
SELECT [mainthistory].[partid], [mainthistory].[maintdate], [mainthistory].[initials], [mainthistory].[status], [mainthistory].[notes], [mainthistory].[Maint_id], [partstable].[partkey], [partstable].[manukey], [partstable].[enditemkey], [partstable].[description], [partstable].[enditem], [partstable].[partnumber], [partstable].[serialnumber], [partstable].[stocknumber], [partstable].[location], [partstable].[quantity], [partstable].[datepurchased], [partstable].[manupart], [partstable].[manuserial], [partstable].[manustock], [partstable].[notes], [partstable].[maintinterval], [partstable].[btu], [partstable].[warranty], [partstable].[warranty_expires], [partstable].[loaned], [partstable].[loaned_to], [partstable].[loaned_date], [partstable].[return_date], [partstable].[part_id]
FROM mainthistory RIGHT JOIN partstable ON [mainthistory].[partid]=[partstable].[part_id];
This works fine except for one thing:
It shows a record for each date regardless of if the next_maint is pending or completed. So it actually shows two records, or more if there is multiple entries in the maint_history_T for a part. I only want one displayed, that being the next_maint_date ONLY if the status = 'Pending' otherwise just return null, etc.
Any help would be greatly appreciated. I hope my long winded explanation did not confuse anyone.
Thanks,
Shannan
I want to display all the parts in the parts table and a field called next_maint in Maint_history_T only if a field called status = 'Pending' in the Maint_history_T otherwise I want to leave the next_maint field blank in the recordset.
I tried something like this:
SELECT [mainthistory].[partid], [mainthistory].[maintdate], [mainthistory].[initials], [mainthistory].[status], [mainthistory].[notes], [mainthistory].[Maint_id], [partstable].[partkey], [partstable].[manukey], [partstable].[enditemkey], [partstable].[description], [partstable].[enditem], [partstable].[partnumber], [partstable].[serialnumber], [partstable].[stocknumber], [partstable].[location], [partstable].[quantity], [partstable].[datepurchased], [partstable].[manupart], [partstable].[manuserial], [partstable].[manustock], [partstable].[notes], [partstable].[maintinterval], [partstable].[btu], [partstable].[warranty], [partstable].[warranty_expires], [partstable].[loaned], [partstable].[loaned_to], [partstable].[loaned_date], [partstable].[return_date], [partstable].[part_id]
FROM mainthistory RIGHT JOIN partstable ON [mainthistory].[partid]=[partstable].[part_id];
This works fine except for one thing:
It shows a record for each date regardless of if the next_maint is pending or completed. So it actually shows two records, or more if there is multiple entries in the maint_history_T for a part. I only want one displayed, that being the next_maint_date ONLY if the status = 'Pending' otherwise just return null, etc.
Any help would be greatly appreciated. I hope my long winded explanation did not confuse anyone.
Thanks,
Shannan