Also, "sum(nvl(npayment,0))" is probably better as "Nvl(sum(npayment),0)"