Hi Guys,
this query works fine:
SELECT pol.policy_no,
pl.planno,
pl.plan_name,
NVL(MAX(pol.pol_stat),' '),
NVL(MAX(d.description),' ') stat_descn,
NVL(SUM(ua.units_allocated * fv.bid_price), 0) pol_value,
NVL(MAX(psc.fees), 0) penalty,
c.description
FROM Plan_Surr_Charges psc, Fund_Values fv, Descriptions_Tbl d, currency_tbl c, Ua_Holdings ua, plan pl, POLICY pol
WHERE ua.siteno = fv.siteno
AND fv.siteno = pol.siteno
and pol.siteno = pl.siteno
and pl.siteno = c.siteno
AND pol.siteno = psc.siteno
AND pol.siteno = _siteno
AND ua.fundno = fv.fundno
AND ua.curr_no = fv.curr_no
and ua.curr_no = c.curr_no
AND fv.price_date =
(SELECT MAX(fv2.price_date)
FROM Fund_Values fv2
WHERE fv2.siteno = fv.siteno
AND fv2.fundno = fv.fundno
AND fv2.curr_no = fv.curr_no)
AND pol.planno = psc.planno
and pl.planno = pol.planno
AND ua.pol_ref_no = pol.pol_ref_no
AND pol.pol_stat IN ('A', 'U', 'x', 'D')
AND d.NAME = 'status'
AND d.c_code = pol.pol_stat
GROUP BY pl.planno, pl.plan_name,pol.policy_no, c.description
HAVING SUM(ua.units_allocated * fv.bid_price) <= MAX(psc.fees)
but the results are real slow cos it has to search through all the fund values in the table. Any idea how I can speed this up?
Thanks alot
this query works fine:
SELECT pol.policy_no,
pl.planno,
pl.plan_name,
NVL(MAX(pol.pol_stat),' '),
NVL(MAX(d.description),' ') stat_descn,
NVL(SUM(ua.units_allocated * fv.bid_price), 0) pol_value,
NVL(MAX(psc.fees), 0) penalty,
c.description
FROM Plan_Surr_Charges psc, Fund_Values fv, Descriptions_Tbl d, currency_tbl c, Ua_Holdings ua, plan pl, POLICY pol
WHERE ua.siteno = fv.siteno
AND fv.siteno = pol.siteno
and pol.siteno = pl.siteno
and pl.siteno = c.siteno
AND pol.siteno = psc.siteno
AND pol.siteno = _siteno
AND ua.fundno = fv.fundno
AND ua.curr_no = fv.curr_no
and ua.curr_no = c.curr_no
AND fv.price_date =
(SELECT MAX(fv2.price_date)
FROM Fund_Values fv2
WHERE fv2.siteno = fv.siteno
AND fv2.fundno = fv.fundno
AND fv2.curr_no = fv.curr_no)
AND pol.planno = psc.planno
and pl.planno = pol.planno
AND ua.pol_ref_no = pol.pol_ref_no
AND pol.pol_stat IN ('A', 'U', 'x', 'D')
AND d.NAME = 'status'
AND d.c_code = pol.pol_stat
GROUP BY pl.planno, pl.plan_name,pol.policy_no, c.description
HAVING SUM(ua.units_allocated * fv.bid_price) <= MAX(psc.fees)
but the results are real slow cos it has to search through all the fund values in the table. Any idea how I can speed this up?
Thanks alot