Hi,
Off the top of my head you could try subquerying
select stuff,
(case when ordr = O then (selct ordr.doctotal where ordr=t0tables) else
case when ODLN = O then (select odln.doctotal where odln.docentry=t0tables) else
)
from tables t0
where something
something like that occurs to me
you use 'case when' to check your document's status and invoke the docentry from the primary query to each of the 'case when'
the syntaxis is not right but I hope you get the point
let me know if this sets you in the right direction
Best Regards