0
votes

I am trying to create a report in crystal reports 11 based on this sql query

SELECT *
    FROM (table) OM, (table) OL, (table) C
    WHERE OM.ORDER = OL.ORDER
    AND OM.COMPANY = C.COMPANY
    AND (EXISTS (SELECT *
            FROM (table) OSD, (table) OSDD
            WHERE OSD.ORDER = OL.ORDER
            AND OSD.LINE = OL.LINE
            AND OSD.REVISION = OL.REVISION
            AND OSD.DIM = OSDD.DIM
            AND OSDD.SHAPE = OL.SHAPE))

I thought the best way to start was by creating the main report using the first two tables and creating a subreport using the "EXISTS" section of the query and linking back to the main report.

My details section contains both data from the main report and the subreport. I get the correct results back for where the subreport returns a value, but I want to be able to suppress the detail section of the main report if the subreport is null, but I can't find a way to reference the subreport in any of the selection formulas.

I am open to suggestions if there is a better way to mimic this query as well.

2

2 Answers

1
votes

There's no reason to use a subreport if you don't want to see any data where the subreport is null. You're overcomplicating the report.

If you still want to do this, the Suppress attribute allows expressions. You would likely have to use a globalvar variable, set the variable based on the subreport but I doubt it would be set prior to the row being displayed.

0
votes

I'm not sure if what type of database you are using, but I believe that you probably can use something like:

select * --you probably should narrow this down instead of using a *
from (table) OM
inner join (table) OL on OM.ORDER = OL.ORDER
inner join (table) C on OM.COMPANY = C.COMPANY
inner join (table) OSD on OSD.ORDER = OL.ORDER 
    and OSD.LINE = OL.LINE 
    and OSD.REVISION = OL.REVISION
    and OSD.DIM = OSDD.DIM
inner join (table) OSDD on OSDD.SHAPE = OL.SHAPE

This is off the top of my head and not tested, but the idea is that it would show all of the records from OM, OL, C, OSD, and OSDD where it found matches. since you are not using a left join on OSD or OSDD you should not have any null rows.

However you could always change those to left outer joins like:

select * --you probably should narrow this down instead of using a *
from (table) OM
inner join (table) OL on OM.ORDER = OL.ORDER
inner join (table) C on OM.COMPANY = C.COMPANY
left outer join (table) OSD on OSD.ORDER = OL.ORDER 
    and OSD.LINE = OL.LINE 
    and OSD.REVISION = OL.REVISION
    and OSD.DIM = OSDD.DIM
left outer join (table) OSDD on OSDD.SHAPE = OL.SHAPE

This would give you all rows from OM, OL, and C and only the rows from OSD and OSDD where it found a match. Then you have a number of options to suppress the rows you do not wish to see such as using the he suppress formula in the section expert as rexem suggested.

Hope this helps.