I am working on a stored procedure. I have a table called #CashFlow that contains data for a period of time.
FundID TradeDate Amount
1 1/1/2004 123.00
1 6/30/2006 100.00
2 1/1/2004 100.00
2 3/15/2010 150.00
3 1/1/2010 100.00
I also have a table called #Funds that contains a list of fund identifier that interests me. (There is a bunch of processing that I won’t bore you that generates this list of funds for me) For example, suppose that in my table #Funds there are only IDs 1 and 2 (3 is excluded).
I have three time periods (all ended on "8/31/2010") from 01/01/2004, 1/1/2006 and 1/1/2010, and I would like to combine the amount of three periods.
I tried something like this:
select sum(c1.amount), sum(c2.amount), sum(c3.amount)
from
inner join
inner join
inner join
, ( , ). , , , ou.
, :
select
(select sum(Amount) from #Cashflow c inner join #fundtable f on c.fundid = f.fundid where tradedate between '1/1/2004' and '8/31/2010') as 'Period1',
(select sum(Amount) from #Cashflow c inner join #fundtable f on c.fundid = f.fundid where tradedate between '1/1/2006' and '8/31/2010') as 'Period2',
(select sum(Amount) from #Cashflow c inner join #fundtable f on c.fundid = f.fundid where tradedate between '1/1/2010' and '8/31/2010') as 'Period3'
, - ( )