Friday, March 30, 2012

Report with Multiple Tables Join

I am designing a Receipt using Crystal Reports 8.5 Developer, MS SQL 2000 Server and MS Visual Basic 6.0 sp6. My Receipt will grab some data from RCP, RCPGL, RCPDetail and Customer tables.

SQL = SELECT RCP.RCPID, RCPGL.RCPGLID, RCPDetail.RCPDetailID, RCP.RCPDate, RCP.RCPID, RCPGL.GLDate, RCPGL.ChequeNo, RCPGL.GrossAmount, RCPDetail.InvoiceNo, RCPDetail.AmountPaid, Customer.CustomerName FROM RCP, RCPDetail, RCPGL, Customer WHERE RCP.RCPID=RCPDetail.RCPID AND RCP.RCPID=RCPGL.RCPID AND RCP.CustomerID=Customer.CustomerID AND RCP.RCPID= glngRCPID

Let say RCPDetail has 3 Invoices data and RCPGL has 2 cheque transactions, my SQL query will returns 6 records.

What I want is to display a section with 3 records of Invoice and another section to display 2 lines of cheque transactions.

Anyone can give me some recommendation?Group on the record type. If this is implicit from the data (e.g. ChequeNo is non-0 for cheques) then create a formula to return a type and group on the formula.|||Hi JaganEllis,
Thanks for your suggestion. I have found an idea and it is using grouping too. I will create a temporary table call TempReceipt. I'll SELECT data from RCPGL table and INSERT "RCPGL" as the key into TempReceipt and then SELECT data from RCPDetail table and INSERT "RCPDetail" as the key. After that join the TempReceipt table with Customer table using ADO. When display the data in Report, I'll use Group by the key of TempReceipt to separate the data.sql

No comments:

Post a Comment