I'm getting still about 290 records more than I'm supposed to from a few duplications it's taking in for the results.Any ideas after looking at the below?From looking at the end data I think the duplication is coming from the highlighted section.
select a.clientid,(a.status + ' / ' + a.statusreason) as Status, a.agency as [Plan], a.applid as Applid, a.caseno as Caseno, a.applname as [Member Name],
a.rcvdt as [Date Received],a.fudt as [Callback Date], a.state as State, a.agent as County, a.city as City, a.zip as [Zip Code], b.providerid as [Provider Id],
b.appt_DateTime as [Appointment Date], c.fudate as [Follow Up], d.requirement as Requirement, d.adddttm as [Note Date],
d.notes as Notes
from (table1) e with(nolock)
inner join (table3) a on a.clientid = e.clientid
left join (table2) d with(nolock)
on a.clientid = d.clientid
and a.serial = d.appserial
and d.serial in
(select max(serial) from (table2) with(nolock)
where notes like ('% %')
group by appserial)
left join (table4) b with(nolock)
on e.clientname = b.coid
and a.serial = b.appserial
and b.serial in
(select max(serial) from (table4) with(nolock)
Where appt_status not in ('assessment complete qc','corrections submitted', 'paperwork submitted')
group by appserial)
left join (table5) c with(nolock)
on a.serial = c.appserial
and a.clientid = c.clientid
order by status,applid
select a.clientid,(a.status + ' / ' + a.statusreason) as Status, a.agency as [Plan], a.applid as Applid, a.caseno as Caseno, a.applname as [Member Name],
a.rcvdt as [Date Received],a.fudt as [Callback Date], a.state as State, a.agent as County, a.city as City, a.zip as [Zip Code], b.providerid as [Provider Id],
b.appt_DateTime as [Appointment Date], c.fudate as [Follow Up], d.requirement as Requirement, d.adddttm as [Note Date],
d.notes as Notes
from (table1) e with(nolock)
inner join (table3) a on a.clientid = e.clientid
left join (table2) d with(nolock)
on a.clientid = d.clientid
and a.serial = d.appserial
and d.serial in
(select max(serial) from (table2) with(nolock)
where notes like ('% %')
group by appserial)
left join (table4) b with(nolock)
on e.clientname = b.coid
and a.serial = b.appserial
and b.serial in
(select max(serial) from (table4) with(nolock)
Where appt_status not in ('assessment complete qc','corrections submitted', 'paperwork submitted')
group by appserial)
left join (table5) c with(nolock)
on a.serial = c.appserial
and a.clientid = c.clientid
order by status,applid