sql server 2008 r2 - Sum values of column on a row with null values in the same column -
i have below query generates following table. wonder if there way replace null-value in column "rate" sum(yieldportion) 5 currencies includes data every position date? preferable in case-clause generates "rate".
positiondate| currency | yield | ratename | rate | yieldportion 2017-03-27 | dkk | -7,0 | cibor_3m | -24,750 | -0,058 2017-03-27 | eur | -21,2 | euribor_3m | -33,000 | -0,069 2017-03-27 | nok | 138,6 | nibor_3m | 94,000 | 0,114 2017-03-27 | sek | 5,5 | stibor_3m | -49,100 | -0,195 2017-03-27 | usd | 122,8 | libor_3m | 115,130 | 0,045 2017-03-27 | portfolio| 18,5 | benchmark | null | null 2017-03-24 | dkk | -7,1 | cibor_3m | -24,750 | -0,056 2017-03-24 | eur | -21,1 | euribor_3m | -33,000 | -0,068 2017-03-24 | nok | 139,4 | nibor_3m | 96,000 | 0,118 2017-03-24 | sek | 6,1 | stibor_3m | -49,900 | -0,201 2017-03-24 | usd | 122,3 | libor_3m | 115,680 | 0,046 2017-03-24 | portfolio| 18,6 | benchmark | null | null
.
select yld.positiondate, yld.currency, yld.yield, 'ratename' = case when yld.currency = 'portfolio' 'portfoliobenchmark' else intr.ratename + '_3m' end, 'rate' = case when yld.currency <> 'portfolio' intr.mid*100 else null end, 'yieldportion'= ssi.mvweight*intr.mid position.tbl_yield2 yld left join position.vw_interestrates intr on yld.currency = intr.currency , yld.positiondate = intr.ratedate , intr.ratename '%ibor%' , intr.timeband = '3 months' left join --below query calculates each currency's portion of portfolio's market value ( select mvc.positiondate, currency, mvccy/mvportfolio mvweight ( select --calculation of mv / currency positiondate, currency, 'mvccy' = sum(mvcleanccy*spot) position.vw_positions instrumentgroup not in ('overnight deposit', 'foreign exchange') group positiondate, currency )mvc inner join (select -- calculation of mv portfolio positiondate, 'mvportfolio' = sum(mvcleanccy*spot) position.vw_positions instrumentgroup not in ('overnight deposit', 'foreign exchange') group positiondate )mvp on mvc.positiondate = mvp.positiondate ) ssi on ssi.positiondate = yld.positiondate , ssi.currency = yld.currency
Comments
Post a Comment