Aijaz Chauhan
Aijaz Chauhan

Reputation: 1649

How to get data based on main report in subreport

let me show you my data first

here is my first table Table1

123

and here is second table ('refid' is foreign key to 'id' in Table1) Table2

345

Now i need report something like shown below

565333

this report showing all items from main table with sub items which have value between 0 and 2 here the box of sub item is sub report.

so how do i do it in crystal report?

I have to tried bind main report that includes all the main item but i have no idea how to bind sub report

Upvotes: 1

Views: 1083

Answers (1)

aMazing
aMazing

Reputation: 1460

You can achieve all of this in just one report that is you dont need a subreport.

1) Start by building a report based on the following query that add appropriate tables and join them:

SELECT * FROM TABLE1 t1
    INNER JOIN TABLE2 t2 on t1.id = t2.refid

2) Create 2 Groups in your report. Group1: Table1.id and Group2: Table2.id

3) Once done, add the table1.Name field under Group1 and table2.Item and table2.Value under Group2.

4) On Group2, add your column headers.

5) On the Details sections, insert your data fields, add Suppression formula on Details section {table2.value} < 0 AND {table2.value} > 2. This will hide this section when value is NOT between 0 and 2.

5) Create a text field with text "No Rows found"

6) Then right click Details section, click Insert section below (adds another detail section) and insert the field created above in this section.

7) Right click Detail section B, and add suppression formula {table2.value} > 0 AND {table2.value} < 2. This will hide this section when value is between 0 and 2.

8) If you want Totals for value, on the GroupB Footer, insert a summary from Group2.Value field.

Upvotes: 1

Related Questions