Professional Documents
Culture Documents
where
IsPresentMbs=1 and
exists(Select 1 from TOLLPLUS.MbsInvoices mi with(nolock) where mh.MbsId=mi.MbsId
and mi.AgeStageID=1 )
and exists(Select 1 from TOLLPLUS.MbsInvoices mi with(nolock) where
mh.MbsId=mi.MbsId and mi.AgeStageID=2 )
and exists(Select 1 from TOLLPLUS.MbsInvoices mi with(nolock) where
mh.MbsId=mi.MbsId and mi.AgeStageID=3 )
and not exists(Select 1 from TOLLPLUS.MbsInvoices mi with(nolock) where
mh.MbsId=mi.MbsId and mi.AgeStageID=4 )
and not exists(Select 1 from TOLLPLUS.MbsInvoices mi with(nolock) where
mh.MbsId=mi.MbsId and mi.AgeStageID=5 )
and not exists(Select 1 from TOLLPLUS.MbsInvoices mi with(nolock) where
mh.MbsId=mi.MbsId and mi.AgeStageID=6 )
order by 1 desc