(select
cast(round(sum(port1.market/1000*secr1.moody_rating_no)/
(select sum(port2.market/1000)
from TblHNWPort port2,TblHNWSecr secr2
where port2.cusip = secr2.cusip
and port2.key_date = secr2.key_date
and port2.port_no=port.port_no ),2) as decimal(18,0))
from TblHNWPort port1,TblHNWSecr secr1
where port1.cusip = secr1.cusip
and port1.key_date = secr1.key_date
and port1.port_no=port.port_no
and port1.mod_secr_type not in ('04','05')
and secr1.moody_underlying_rating!='NR')
(select sum(port2.market/1000)
from TblHNWPort port2,TblHNWSecr secr2
where port2.cusip = secr2.cusip
and port2.key_date = secr2.key_date
and port2.port_no=port.port_no ),2) as decimal(18,0))
from TblHNWPort port1,TblHNWSecr secr1
where port1.cusip = secr1.cusip
and port1.key_date = secr1.key_date
and port1.port_no=port.port_no
and port1.mod_secr_type not in ('04','05')
and secr1.moody_underlying_rating!='NR')