I develop an Account program with Delphi7 and design report with Fastreport4 I have a Bill tables that has 6 columns (BillID, BillDate, BillDesc, BillPrice, DebitID, CreditID) that DebitID and CreditID is integer value and in relationship with Account table that hase two columns(AccID, AccName). I want create a report with FastReport in Delphi7 that has this result with these columns:

Report Name : Balance for Mr.x

BillID , BillDate ,  BillDesc    , DebitPrice , CreditPrice , Remain
-----------------------------------------------------------------
1      , 2012/01/22, Sample Desc1, 100USD     , 0           , -100USD
1      , 2012/01/22, Sample Desc2, 0          , 100USD      ,  0USD

I think that if I can create a SQL query with above result it's easy for creating report. if u have any idea, pls let me know?

有帮助吗?

解决方案

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

其他提示

Try subquery

select a.BillID, a.BillDate, a.BillDesc,
(select b.BillPrice from Bill b inner join Account c on b.DebitID=c.AccID
where b.BillID=a.BillID) as DebitPrice,
(select d.BillPrice from Bill d inner join Account e on d.CreditID=e.AccID
where d.BillID=a.BillID) as CreditPrice
from Bill a

I didn't test it but I think its gonna work, please let me know about it

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top