select BillID , BillDate ,BillPrice, BillDesc, b.accid, c.accid
from a Bill
left outer join account b on a.DebitID = b.AccID
left outer join account c on a.CreditID = c.AccID
then, you must evaluate "on before print event" of your masterdata/detaildata band.
if (b.accid <> '') then
DebitPrice := BillPrice
else
CreditPrice := BillPrice
Note : DebitPrice, CreditPrice are global variable