If I have this below. How can I have it return dates where no activity happened so it will return zero values and I can pivot it and have all dates on top with counts below it? Right now it pulls all the dates for what I'm asking. The tables do not have all date stamps in them, so this would be some sort of statement to define that..
select a.ClientName,d.clientid,e.agency,a.clerk, a.dttime, a.appserial, b.appt_datetime
from vwhistory_acct0 a with(nolock)
inner join vwacc d
on a.clientname = d.clientname
left outer join vw0 e
on a.appserial = e.serial
and e.clientid = d.clientid
left join hhapp b with(nolock) on a.appserial = b.appserial and b.COID = a.ClientName
and b.serial in
(select max(serial) from hhapp with(nolock)
where appt_status in ('Appointment Complete','Appointment Pending')
group by appserial,coid)
where a.serial in ( select min(serial) from vwhistory_acct0 with(nolock) where
[Status] = 'scheduled'
and ClientName = a.ClientName
group by appserial,ClientName)
select a.ClientName,d.clientid,e.agency,a.clerk, a.dttime, a.appserial, b.appt_datetime
from vwhistory_acct0 a with(nolock)
inner join vwacc d
on a.clientname = d.clientname
left outer join vw0 e
on a.appserial = e.serial
and e.clientid = d.clientid
left join hhapp b with(nolock) on a.appserial = b.appserial and b.COID = a.ClientName
and b.serial in
(select max(serial) from hhapp with(nolock)
where appt_status in ('Appointment Complete','Appointment Pending')
group by appserial,coid)
where a.serial in ( select min(serial) from vwhistory_acct0 with(nolock) where
[Status] = 'scheduled'
and ClientName = a.ClientName
group by appserial,ClientName)