Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Comparing Result Set

Author  Topic 

callawayx14
Yak Posting Veteran

73 Posts

Posted - 2007-08-09 : 13:16:29


I’m trying to compare the result set of two separate queries. The problem is I can not create tables to run the comparison. (Including temp tables)

Serial # is shipped on ?Date?

Was that serial number received back to the vendor within 14 days of the shipment?

Fields available to me are

Ship_serial_number|Ship_Date| Recv_serial_number|Recv_Date


Any help will be greatly appreciated

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-08-09 : 13:22:00
So you have to compare (1) Ship_serial_number is same as Recv_serial_number and (2) Ship_Date + 14 days <= Recv_Date?

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

callawayx14
Yak Posting Veteran

73 Posts

Posted - 2007-08-09 : 13:28:51
Yes but the two records will be seperate line items like

ID| Ship_serial_number| Ship_date | Recv_serial_number | Recv_date
1| TEST1 | 01/01/07 | NULL | NUll
2| NULL | NULL | TEST1 | 01/10/07
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-08-09 : 13:38:21
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 all
select 2, NULL , NULL , 'TEST1' , '01/10/07' union all
select 3, 'TEST2' , '01/03/07' , NULL , NUll union all
select 4, 'TEST3' , '01/01/07' , NULL , NUll union all
select 2, NULL , NULL , 'TEST2' , '01/02/07'


select distinct T.Ship_serial_number , T.Ship_date
from @T T

join (
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/
Go to Top of Page

callawayx14
Yak Posting Veteran

73 Posts

Posted - 2007-08-09 : 13:42:21
Thank you!!! This should keep me busy for a bit. I appreciate it!!
Go to Top of Page
   

- Advertisement -