HEre's a sample: I just got the results for IP and P2. You can add the third table appropriately.Declare @Initial_Procedure table (ID int, Person_ID int, Completed_DTTM datetime)Insert into @Initial_Procedure Select 1, 1, '01/10/2007' union allSelect 1, 1, '02/15/2007' union allSelect 1, 1, '02/20/2007' union allSelect 1, 2, '01/02/2007' union allSelect 1, 3, '06/26/2007'Declare @Procedure_2 table( ID int, Person_ID int, Completed_DTTM datetime)Insert into @Procedure_2 Select 2, 1, '01/09/2007' union allSelect 2, 1, '01/15/2007' union allSelect 2, 1, '01/16/2007' union allSelect 2, 1, '01/17/2007' union allSelect 2, 1, '02/19/2007' union allSelect 2, 1, '07/25/2007' union allSelect 2, 1, '09/02/2007' union allSelect 2, 2, '01/01/2007' union allSelect 2, 2, '01/14/2007' union allSelect 2, 2, '01/20/2007' union allSelect 2, 3, '05/04/2007' union allSelect 2, 3, '06/27/2007'Select IP.*FROM @Initial_Procedure IPLEFT JOIN ( Select P.Person_ID, max(P.Completed_DTTM) MaxCompleted from @Procedure_2 P Group by P.Person_ID ) P2 on IP.Person_ID = P2.Person_ID And IP.Completed_DTTM < P2.MaxCompleted(5 row(s) affected)(12 row(s) affected)ID Person_ID Completed_DTTM----------- ----------- -----------------------1 1 2007-01-10 00:00:00.0001 1 2007-02-15 00:00:00.0001 1 2007-02-20 00:00:00.0001 2 2007-01-02 00:00:00.0001 3 2007-06-26 00:00:00.000(5 row(s) affected)
Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/