For simplicity, I have a table – Claims that has memberid and dateof service. My other table – Elig has membered, mineffectivedate and maxeffectivedate. Now a member could have several records in the Elig table. I need to find records where the dateof service is not between any of the Elig records. Example –
Claims table
MemberID DateofService
123456 5/2/2011
Elig Table
MemberID MinEffectiveDate MaxEffective Date
123456 1/1/2011 4/1/2011
123456 6/1/2011 12/31/2011
Because there is a gap in the dates and the claim record is between that gap, I need that record. This is what I’ve started but it isn’t working correctly. Thanks!
select mc.MemberID
from dbo.tbl_MedicalClaims mc left outer join
dbo.vu_MemberEligibility me on mc.MemberID = me.MemberID and mc.FeedID = me.FeedID
where mc.FeedID = '1'
group by mc.MemberID, me.MinEffectiveDate, me.MaxTerminationDate,mc.DateOfService
having mc.DateOfService not between max(me.MinEffectiveDate) and min(me.MaxTerminationDate)
Claims table
MemberID DateofService
123456 5/2/2011
Elig Table
MemberID MinEffectiveDate MaxEffective Date
123456 1/1/2011 4/1/2011
123456 6/1/2011 12/31/2011
Because there is a gap in the dates and the claim record is between that gap, I need that record. This is what I’ve started but it isn’t working correctly. Thanks!
select mc.MemberID
from dbo.tbl_MedicalClaims mc left outer join
dbo.vu_MemberEligibility me on mc.MemberID = me.MemberID and mc.FeedID = me.FeedID
where mc.FeedID = '1'
group by mc.MemberID, me.MinEffectiveDate, me.MaxTerminationDate,mc.DateOfService
having mc.DateOfService not between max(me.MinEffectiveDate) and min(me.MaxTerminationDate)