Advanced Report Writing
Advanced Report Writing
Contents
Target Audience.................................................................................................................................2
Overview .............................................................................................................................................2
Top x Rows.........................................................................................................................................2
Standard Computed Fields ...............................................................................................................2
Overview ........................................................................................................................................2
Report Designer Computed Field...............................................................................................3
Overview....................................................................................................................................3
Calculated Values......................................................................................................................3
Combining Text and Fields.....................................................................................................4
SQL Select Computed Column...................................................................................................6
Overview....................................................................................................................................6
How to Access the Functions List .........................................................................................7
Examples of Use.......................................................................................................................7
Sub-Queries – Nested Select............................................................................................................9
Overview ........................................................................................................................................9
Method............................................................................................................................................9
Common Mistakes ......................................................................................................................10
Worked Example.........................................................................................................................10
Nested Reports.................................................................................................................................11
Overview ......................................................................................................................................11
Creating Nested Reports............................................................................................................11
In brief......................................................................................................................................12
The master report ...................................................................................................................12
The sub-reports.......................................................................................................................12
Tying the reports together.....................................................................................................12
Queries in Computed Fields ..........................................................................................................15
Overview ......................................................................................................................................15
Summary Method........................................................................................................................15
Overview..................................................................................................................................15
Worked Example ....................................................................................................................15
Result Dependant Method.........................................................................................................17
Target Audience
This document is for use by ProspectSoft CRM Resellers’ staff who have completed
the Report Writer Basic & Intermediate course and want to move on to Advanced
report writing.
Overview
This document is an Advanced guide to report writing and should be used for writing
complex reports in different styles. At times throughout this document it is
recommended that a copy of the Introduction to InfoMaker document is at hand to
help locate the required buttons and formatting options.
Top x Rows
This statement will allow the report to return only the top x number of records from a
query, a practical use of this could be for graph reports, where the report user only
wants to know about their top 20 customers. To use this function, convert the SQL
Select screen to syntax, then type after select, top x. Example:
Select top 20 “dba”.”division”.”divno”,
“dba”.”division”.”divname”
From “dba”.”division”
Where ………..
This will only select the top 20 returns and the outputted results will depend highly on
the orderby statement used. (This is the sort defined in the SQL Select screen.)
Warning: once an SQL select statement has been modified in this way, it may not be
possible to convert back to graphics, ensure that the query is working correctly before
attempting this.
Overview
The Report Designer Computed fields are created in the Report Designer Screen and
can be used in most of the different report styles.
This type of Computed Field is used to display calculated values based on the results of
the report or to combine text and fields together to make a report look better.
Calculated Values
In order to calculate values in the report output, all variables to be calculated on must
be selected in the SQL Select Screen. For example if the report being written is about
problems, the end-user may want to know how old each problem being returned is.
To do this, ensure that the “created” field from the problem table is selected in the
SQL Select Screen. Then, in the Report Designer Screen click ‘insert’, ‘control’ then
‘computed field’. Next, click where the computed field is to appear.
Note: As this example will return a different result on each row returned, it is
important that the computed field is placed in the detail section.
After inserting the computed field, the expression builder appears:
Using the functions list on the left it is possible to do all sorts of calculations. The
function needed for the above example is ‘daysafter(x,x)’ this function simply
calculates the number of days difference between two dates. In order for the above
computed field to work the function will calculate the number of days between the
created date and when the report was run. In order to return today’s date into a report
the ‘today()’ function can be used.
For the sake of consistency a title should be added for the computed field (column).
Another example of this is to group fields together to display them in an easier way.
For example, in the above report the contact details are split into title, forename and
surname, by using a computed field all these values can be combined into one field.
The existing title, forename and surname fields can be deleted from the report design
(do not delete them from the SQL Select as they will be needed for the computed
field). Insert the computed field as before, except that instead of being placed in the
‘header’ section it would be placed in the ‘detail’ section.
Note: In order to sort in a logical way for the above example, the sort would need to
work by surname. Rename the header field to contact_surname_t and insert the
surname field back into the report. This field can be made invisible and will only be
used to sort the data.
Overview
The SQL Select Computed field is used to create a computed field at the point or
retrieval. The advantage of using this method of creating computed fields is that the
computed field can then be used in the where clause, or if used in graph reports or
crosstab report they can be used as values or categories.
The computed column is created in the ‘compute’ tab in the SQL Select Screen.
Examples of Use
In a crosstab report about sales history it might be good to display values (sales income
or quantity sold) split by the date that they sales were invoiced, if the crosstab report
was to use the invoice date field from within ProspectSoft CRM as the column each
different date that an invoice was raised on would have a column to itself, the output of
a report such as this would be un-manageable (even for a small sales history). With the
use of the SQL functions list the invoiced could be grouped by year, then quarter or
month or even week.
In the computed columns section the syntax would appear like so:
If these computed columns were returned into a grid report the results would appear
like so:
Method
The first thing to do is to build the report that will return the master list, the master list
should contain all possible results before attempting to remove that which is not
required.
Common Mistakes
Mismatch of primary keys, make sure that the field used in the where clause is the same
as the field returned from the sub-query.
‘Master List’ includes unnecessary tables, it is habit to include tables that are not
required, in the above example it is natural to include the contact table right from the
beginning, this will make the report in-accurate as the division will need a contact in
order for it to be returned in the master list, a division with no contacts however
should appear in a list of divisions with no decision maker.
= operator used, when using sub-queries for this purpose, the ‘not in’ operator must be
used.
Worked Example
To re-create the above example, the first step is to create the master list, as the
requirements for this report are quite simple the only table required in the SQL Select is
the division table.
If this report was to be run it would return a list of all the division names in the
database. Now the report needs to take away all the division that have a decision
maker, to do this select divno as the column in the ‘where’ clause, then change the
operator to ‘not in’ right-click in the ‘value’ section and choose ‘Select’.
Click the ‘return’ button to go back to the main select, and then click return to proceed
to the Report Designer.
Nested Reports
Overview
The Nested Reports technique is a way of running multiple reports at once, and tying
them together in a simple way, this style of report writing is mainly used for summary
reports.
The sub-reports
Create two grid reports (in a working example any report style for the sub-reports can
be used, but for simplicity in this example grid style reports will be used as it is quicker
and easier to do), the first report should select appropriate lead information from the
lead and contact table, the second report should select appropriate problem
information from the problem and contact table, both reports will need a retrieval
argument against the contact.divno, the retrieval argument must be of type ‘number’ as
this report is comparing numeric values.
(Note: when doing retrieval arguments against divno, contno, etc. the report would
normally use the argument type of ‘string’, this is because ProspectSoft CRM would
normally return a string for xtratab forms and reports, in this case the comparison is
made with the report, not the software, so the ‘number’ argument type must be used)
End result:
Summary Method
Overview
By using the queries in computed fields technique it would be totally possible to display
in one report information from entirely un-related areas of the database, for example a
report that showed company performance for a period.
The detail of the above report would depend largely on what measures were used to
monitor company performance, but at a crude level the report could return the number
of problems created, the number of leads created and the number of quotes created.
These values could be vastly refined to show more appropriate statistics.
For this example a ‘freeform’ report style would be the most appropriate to use.
In the SQL Select screen, when prompted with the table list, select ‘Show System
Tables’, then choose the “sys”.“dummy” table. No fields will be selected from this
table, but InfoMaker requires a table to be selected in every select screen.
In the above example the report will return 3 values, the count of leads, problems and
quotes, these 3 values need to be created as computed fields.
Worked Example
It is recommended that when creating this type of computed field the user builds it up
gradually, for the above example, although the aim is to count the number of leads
created during a period, this computed field will just count all the leads in the database
for the time being. The syntax for this would appear as so:
Overview
The result dependant method of queries in computed fields is used to return one of a
number of values into each line of a report, based on an existing value returned.
A good example of this is a list of divisions with a total of their sales history. This
could be done with a group report, by hiding the detail section and summing all of the
transaction lines returns, however if the report is made in this fashion the user of the
report will be unable to drilldown as there is no detail section available to select.
The result dependant method of this report will return a list of the required divisions
and include a computed field that will work out the sales history for that division.
Worked Example
First create the report that will return the required list of divisions (a grid report will
do), for this example the report will return all of the divisions that are of a ‘Customer’
company type. It is important that in the main report the sales history table is not
included.
At the moment this computed field will return the sum of the whole sales history table
and display for each division.
To tie the sum of the sales history the computed field needs to reference results that
are returned in the main report, to this add a where clause to the computed field to
effectively ‘join’ the division table in the main report to the sales history table in the
computed select.
This ‘join’ now means that for each division returned in the main report the computed
field will be run and will return just the sales history for that division.
Other considerations:
In most ProspectSoft CRM systems the sales history table would also contain values
for orders, so the where clause should be written to ignore these.
The value return from the above select would be return as an integer (the original
format for that field) this means that even if the field was divided to the correct
number of decimal places, it would still remain an integer, the cast function can be used
to convert the integer to a floating decimal or fixed numeric value.
Note: in the result dependant method, the computed fields returned can be used in the
where clause, for example to only return divisions with a high enough sales history
total.