aajay
Technical User
- Oct 28, 2004
- 36
I’m new bee
I wrote store proc following
select sum(a.Amount) as amount1
,sum(b.Amount)as amount2
,'Agencies' as CategoryName
from DMAS_INFO di
left outer join
(select sum(Amount) as Amount
,ADISID -—current year
from vwGiving_Gift_Journal_Rpt
where TransactionType=1
and month(DateProcessed) = 4
and year(DateProcessed) = 2007
group by ADISID ) a
on a.ADISID=di.ADISID
left outer join
(select sum(Amount)as Amount
,ADISID -- year to date
from vwGiving_Gift_Journal_Rpt
where TransactionType=1
and FiscalYear = 2007
and DateProcessed < '4/26/2007'
group by ADISID)b
on b.ADISID=di.ADISID
where di.CATEGORY = 'L'
It runs, but verty slow, Plus I have to do 6 more union to get different conditions join for every di.CATEGORY e.g ‘M’,’N’,’Y’,’Z’
Would any one look at and let me know what would be the best way to do this store proc specially when I'm doing sum(a.Amount)
thanks
I wrote store proc following
select sum(a.Amount) as amount1
,sum(b.Amount)as amount2
,'Agencies' as CategoryName
from DMAS_INFO di
left outer join
(select sum(Amount) as Amount
,ADISID -—current year
from vwGiving_Gift_Journal_Rpt
where TransactionType=1
and month(DateProcessed) = 4
and year(DateProcessed) = 2007
group by ADISID ) a
on a.ADISID=di.ADISID
left outer join
(select sum(Amount)as Amount
,ADISID -- year to date
from vwGiving_Gift_Journal_Rpt
where TransactionType=1
and FiscalYear = 2007
and DateProcessed < '4/26/2007'
group by ADISID)b
on b.ADISID=di.ADISID
where di.CATEGORY = 'L'
It runs, but verty slow, Plus I have to do 6 more union to get different conditions join for every di.CATEGORY e.g ‘M’,’N’,’Y’,’Z’
Would any one look at and let me know what would be the best way to do this store proc specially when I'm doing sum(a.Amount)
thanks