The query below suppose to find out some project info (resource id and project id etc) and work out the "last assignment date". However, it creates a problem when there are is a month change during the week e.g Jan 07 finishes on Wednesday and Feb 07 starts on Thursday. It should only give one "last assignment date" for one "project id" with each "WeekCommencing". Since the week got split into two months. It is giving two "last assignment date" with the same "project id" with each "WeekCommencing". one for Jan and one for Feb. Can anyone suggest a way I can remove the earlier (Jan) one and keep the latest one (Feb)? Any help will be appreciate.
The Query
****************************************
SELECT X.RES_ID, X.PROJ_ID, X.WeekCommencing, [WeekCommencing]+(Right(IIf([monday]>0,0) & IIf([tuesday]>0,1) & IIf([wednesday]>0,2) & IIf([thursday]>0,3) & IIf([friday]>0,4) & IIf([saturday]>0,5) & IIf([sunday]>0,6),1)) AS LastAssignedDate
FROM X INNER JOIN Y ON (X.WeekCommencing = Y.WeekCommencing) AND (X.PROJ_ID = Y.PROJ_ID) AND (X.RES_ID = Y.RES_ID);
****************************************
The Query
****************************************
SELECT X.RES_ID, X.PROJ_ID, X.WeekCommencing, [WeekCommencing]+(Right(IIf([monday]>0,0) & IIf([tuesday]>0,1) & IIf([wednesday]>0,2) & IIf([thursday]>0,3) & IIf([friday]>0,4) & IIf([saturday]>0,5) & IIf([sunday]>0,6),1)) AS LastAssignedDate
FROM X INNER JOIN Y ON (X.WeekCommencing = Y.WeekCommencing) AND (X.PROJ_ID = Y.PROJ_ID) AND (X.RES_ID = Y.RES_ID);
****************************************