Won't this be enough
Use OSPR_WorkArea
Declare @BeginDte Smalldatetime; --<<<< Enter the beginning time frame
Set @BeginDte = '07/01/2011'; --<<<< Enter date in this format: '04/01/2007'
Declare @EndDte Smalldatetime; --<<<< Enter the ending time frame
Set @EndDte = '06/30/2012'; --<<<< Enter date in this format: '04/30/2007'
Select appid,
Count(distinct wp.appid) participants,
Count(svp.*) srvs2partx ,
SUM(Case When servicecode between '750' and '882' then 1 Else 0 End) partxPlaced,
SUM(Case When servicecode in ('210','211') then 1 Else 0 End) ref2svcs,
from DOLETA.dbo.wp_9002_20114 wp
inner join efmextract.dbo.serviceplan svp on wp.appid = svp.programappid and svp.programid = 3
and rgn = '01'
and Black = '1'
and Gender = '1'
and programparticipationdate <= @EndDte
and (programexitdate >= @BeginDte or programexitdate is null))