HEre's something that might give you some direction:Declare @T Table (ID int, Ship_serial_number varchar(10), Ship_date datetime, Recv_serial_number varchar(10), Recv_date datetime)insert into @T select 1, 'TEST1' , '01/01/07' , NULL , NUll union allselect 2, NULL , NULL , 'TEST1' , '01/10/07' union allselect 3, 'TEST2' , '01/03/07' , NULL , NUll union allselect 4, 'TEST3' , '01/01/07' , NULL , NUll union allselect 2, NULL , NULL , 'TEST2' , '01/02/07'select distinct T.Ship_serial_number , T.Ship_datefrom @T Tjoin ( select distinct T2.Recv_serial_number RSN, T2.Recv_date RD from @T T2 Where T2.Recv_serial_number is not null and t2.Recv_date is not null ) Rec on T.Ship_serial_number = Rec.RSN And T.Ship_date <= dateadd(dd,14,Rec.RD)Where T.Ship_serial_number is not null and t.Ship_date is not null
This will give you items that were received within 14 days of ship date.Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/