55.1.13 Summary: Grid Area page: Slave Query
Except for Place Holders, this area behaves in a very similar manner to the Query area as described in the Chapter Reports: Query Store on page 427.
For details on setting Placeholders see the Master Query Section on page 370
Every Grid Envelope MUST have a Slave Query attached to it.
The Slave Query is evaluated only once for the Grid Envelope. It determines the Current Selection of Records that is used to calculate the Statistics defined by the Grid Items contained in the Grid Envelope.
If you do not explicitly define a Slave Query then the Current Selection of Records for the Table that the Field Grid Envelope belongs to is set to zero - there are no records in the selection to evaluate!
For instance you may wish to calculate the Max, Min and Mean of the Age at Admission of a selection of Admission records.
This would be done by defining a Grid Envelope called [ICURecord]Adm_Age_InYears. Then define a Slave Query that creates a Selection of Records in the [ICURecord] table. Next define the required Statistic Grid Items to calculate the Min, Max and Mean of the Age from the selected records and display the result on the Grid. Clearly the same Selection of Records would be used to calculate Min, Max and Mean. This is why the Slave Query is attached to the Grid Envelope rather than the Grid Item - many Grid Items may be created and linked to a Grid Envelope and its Slave Query.
You will often come across the terms Selection and Set in this section. Knowing the difference is CRUCIAL in order to understand what is going on as you construct your Query.
Here is a definition of a Selection
A Selection is an object that may contain some records from a single Table. For EVERY Table in the database there is ONE selection of records. This selection may be EMPTY i.e. have no records in it.
A Set is an object that tells STATIC which records from a Table are contained in the Set. For EVERY Table in the database there can be MANY Sets - if you have enough memory.
Note: In STATIC a Set is an array of Boolean values in which EVERY record for a Table is represented. If a record is in the Set then it is represented by a 1, if it is not in the Set then it is represented by a 0. As Sets are basically arrays, and because arrays are manipulated in memory, Set operation is very fast - almost instantaneous.
Conversion of Set and Selection
You can convert a Set to a Selection by the command Use Set.
You can convert a Selection to a Set by the command Create Set
Note that almost every operation in STATIC will create a Set and as a result you will almost never require the Create Set command. This command is left in the command theme for legacy Reports that have not been converted.
Statistics are calculated on a Selection of Records NOT on a Set of Records.
It is crucial that a Slave Query returns a Selection of Records and not a Set of Records. If you do not remember this, you will get strange results - and probably be warned that there are no records to work on for the statistic.
Organize your Query to end with a Use Set command to ensure that you are using the Selection of Records you require.
If you understand the differences between Sets and Selections then you do not always need to do this. Some commands return Selections Automatically. These include the Query, Query By Formula and the Join commands. If the Selection returned by these commands is the selection that you require then it is unnecessary to convert to a Set. We recommend against this as a strategy - it is always better in our experience to define the selection you want to work on by calling the USE SET command.
On the other hand some Statistics REQUIRE you to define at least 2 Sets - the Total Count for 100% Reference Set and % Valid Count of TotalCount.
|