|
|||||||||
|
Crystal Reports Tools: Improve Performance While Saving Time and Money |
|
How to exclude records from one table based on matching records from another tableOur client had a table with some debtors names and addresses. A stored procedure built a list of debtors who met a specific criteria. The report from the join of these two tables worked exactly as planned.
|
||||||||||
|
They then wanted a report to select the original debtors, but excluding those from the criteria table. The working table from the original report still contained the values we wanted to exclude. We could use that table in our new report. A left join would select all debtors, and then a selection formula could be used to look for a NULL value in the exclude table. That's a simple solution. One thing it does is hide irrelevant information. And that's one key purpose of a business intelligence report. Remember, it's not a data dump. But.... |
Click to Enlarge |
||||||||||
|
This doesn't merely hide irrelevant information. It totally excludes it. That means there's no ability to compare debtor list A with the debtor list B. Suppose, for example, debtor list A is the complete list. To develop your debtor B list, you exclude debtors who:
You excluded these because there's no sense in harassing them about their poor repayment history. They are doing fine. It's the other creditors who cause you problems. And it's those creditors you want to see in your debtor B list. But suppose you'd like to know how big the debtor A list is compared to the debtor B list? Suppose you want to track your progress in converting debtor Bs into debtor Cs (those who are excluded)? Or maybe you want to compare the two lists by zip code, with an eye to maximizing the efficiency of collection efforts? The way to do this is to implement the original solution, but as a subreport of your Crystal Report. You could also create a subreport of the inverse (your debtor C list). Subreports are incredibly useful. And you can do them on demand. Tha's a bit tricky to implement. One of our customers was testing one of our User Function Libraries. This function library builds up and then writes a disk file with some data. Our XML, Grid and Disk Output UFLs all do this. You can do all the file writing in one formula or you can build the data up across multiple formulas using data from each section of the report. The final formula writes the data to the disk file. The DiskLinesFinish function did this for him in a formula in the report header section. Our client found a way to control this, by having a simple on-demand subreport with this final formula. This way he could view the report, check it had the correct record count and field values, and then save it to disk by clicking on the on demand subreport. See also: Use an On Demand Subreport to Mimic a Drill Down
Why is there so much interest in subreports? This concept is not new to Crystal Reports. It's been in practice for a long time, in fact. Subreports are common database tools that serve as intermediaries when you can’t create a report directly from multiple data sources. In Access, for example, doing anything across multiple queries or tables requires building a subreport. Crystal Reports doesn’t need the same degree of subreport "propping up" that Access does, but it still makes handy use of subreports. Suppose you have two databases, where each stores the same information—such as employee names, addresses, start dates, and so on. But, the one uses the date format YYYY-MM-DD and the other uses the date format MM-DD-YY. Hmm. Small problem, here. Suppose one table store numbers in a true number field and the other stores them as string variables or text. The only way to resolve such incompatibilities is with a subreport. You create one subreport to standardize the data in one database to the format of the data in the other. Or, if you’re feeling particularly masochistic, you create a subreport for each database, coming up with an entirely new format. Subreports can be linked (they update data as those data change in the source) or unlinked (they contain static data). You would want a linked report if you want "real time" information. You would want a static report under any of these conditions:
Among linked reports, a increasingly popular option is the on-demand subreport. It doesn’t process until you ask it to. It can appear as just a link or some other element (such as a graphic that says, "Update data now.") This has all kinds of benefits which will become apparent as you use it.
A note on linked subreportsLinked subreports are really useful. Link a field or formula from the main report and get the subreport to select records based on that field. But what if your subreport needs the linked parameter for something else? You might want to use it in a calculation, or for conditional grouping, sorting or section suppress. If you don’t use the link for record selection you may find that the link is removed when you exit the subreport link form. The solution is to create the parameter in the subreport prior to creating the link. When you create a link to an existing parameter in the subreport, it is saved when you exit the subreport link form.
This article is copyrighted by Crystalkeen, Mindconnection, and Chelsea Technologies Ltd. It may be freely copied and distributed as long as the original copyright is displayed and no modifications are made to this material. Extracts are permitted. The names Crystal Reports and Seagate Info are trademarks owned by Business Objects. |
|||||||||||