Question : Finding unmatched data between two sql tables

I have two SQL 2000 table:
Table 1: UserID, Date
Table2: UserID, DateOut, DateIn

UserID is used as a join between both tables
table1.Date needs to be matched as a date that falls between table2.Dateout and table2.datein
I need a sql code to first find recods that match in table2 and a seperate code to show all records from table1 that do not have a match in table2.

Answer : Finding unmatched data between two sql tables

Hello sleiman,

you should use use a left outer join then...


select Distinct a.*
       ,case when b.userid is null then 'Unmatched' else 'Matched' end as [Status]
  from table1 as a
  left outer join table2 as b
    pn a.userid=b.userid
  and a.date between b.dateout and b.datein
 order by a.userid





Regards,

Lowfatspread
Random Solutions  
 
programming4us programming4us