Queries |
Content |
|||||||||
|
Overview |
|
|
Purpose |
LabVantage uses queries for three purposes. The primary purpose is to filter a list or lookup page. Users can choose a query and apply this filter making it easier to find the data they need on a list. A second purpose is to determine which data is visible on a Dashboard. Administrators will design Gizmos. Many of these Gizmos support the use queries depending on the Gizmo Type. Lastly, the LabVantage Actions can execute a query. The Query List Page allows you to add or edit standard LabVantage Queries. These execute SDC-centric SQL statements.
Navigate to System Admin > Configuration > Queries
Button | Description |
Add | Standard Add and Edit maintenance page usage shown below. |
Copy | Allows you to copy a current query to create a new query. |
View | Opens a standard View page for the selected query. |
Delete | Removes the selected query/queries from the application. |
Manage Categories | Allows you to view and adjust the categories assigned to the selected queries. |
Reconcile | This invokes the Query Reconciliation page. |
Keep Changes | The selected query or queries will retain your definition for that query. The Controlled Flag will be set to "I" for "ignore the differences between your query definition verses the one supplied by LabVantage". This is your acknowledgement that you accept these differences. |
Reset to Default | The selected query or queries will be altered. The Controlled Flag will be set to "Y" represented by green square icon in the Controlled column. The definition for this query is updated to match what is supplied by LabVantage. |
Configuration Report | Launches a Configuration Report wizard. |
Check In/Check Out View Change History | Standard features of the Configuration Management Tool. |
Export | Standard feature of the Configuration Transfer Tool. |
Show/Hide Records | Sets the Active Flag to either Y or N. Queries that are no longer active will not show on certain lookup pages. |
Controlled Flag |
In the standard Query table, a column: QueryControlledFlag is set to either Y or N by comparing each query to what is in the ProductQuery table along with the detail tables, ProductQueryArg and ProductQueryUnion. The columns compared are:
query.productfromclause
query.productwhereclause
query.productorderbyclause
query.productwithclause,
queryargs.*
queryunions.*
Any query that has this controlled flag set to 'N' will be returned by the query on this list page labeled "Needs Reconciliation". To reconcile, select a query and use the toolbar button to Reconcile. This reconciliation page will show you the differences. From here you can acknowledge the difference and retain your definition, or overwrite your changes to accept the Core definition supplied by LabVantage.
Any query you have acknowledged to be different than the Core definition will be indicated with the letter "I" for ignore. This is represented by the icon .
The Query Reconciliation Page |
When you install LabVantage for the first time, over 600 queries are made available as "Core" queries. You are permitted to make changes to these queries. You can use this page to see what the differences are between your selected definition and the one supplied by LabVantage. You can acknowledge that you would like to retain your changes or reset a query to the Core definition as supplied by LabVantage. Running the "Needs Reconciliation" query from the list page will reveal any query that has not been acknowledged after an upgrade or update. See the Controlled Flag section.
In the example below, the system has identified a core query that is different than the LabVantage definition. A change has been made to the 'where' clause in this case.
In this case, if you click Keep Changes, your definition is retained and the list page will show a green check icon in the Controlled column.
If you click Reset to Default, your definition is overwritten with the definition on the right side of this page. Warning! This reset cannot be undone.
Example Query |
![]() |
All standard queries that perform any relative 'date where' expressions use a substituted date-expression that is inserted into the query and evaluated by the RSET query routines. Examples include after a date, between dates, and others. These date expressions handle
Please see Query Date Handling for more detail.
Description |
|
|
Query |
Fields of the Query form:
Field | Description |
Id | Identifier of the Query SDI. |
Query Label | Name to be displayed for the Query in lieu of the Query Id. Use the "Use Query Label" property of the advancedsearch Element to display this Query Label. |
Description | Description of the Query SDI. |
For SDC
Table |
SDC and table from which the Query retrieves column values. |
From Clause | If you enter nothing in this field, the Query retrieves
information in all key columns of the SDC.
If you want to retrieve information in specific SDC columns, enter the column names in accordance with SQL statement syntax rules of the installed database. |
Where Clause | Where clause for the Query. |
Order By Clause | Row by which the Query sorts (in ascending order) retrieved information. |
Cascaded Arg | When checked, executes a Query using Cascaded Arguments
(resolving each argument based on the previous argument).
When unchecked, executes a Query using Collective Arguments (simultaneously resolving all arguments independently). |
Distinct | When checked, adds the DISTINCT keyword to the SELECT statement. |
Union Query | When checked, opens a detail tab (after saving) to manage additional from and where clauses that are unioned (see Additional Union Clauses). |
Embed Security | Determines whether security-related SQL is added directly to a query WHERE clause (Yes), or security is applied after to the results of the initial query (No). |
Query Limit | This is a numeric column that lets you specify the maximum number of rows returned by the query. |
Optimizer Hint | Optional optimizer hint to provide a mechanism to instruct the DBMS optimizer to choose a certain query execution plan based on specific criteria. This requires knowledge of optimization for your DBMS. |
With Clause | Optional With clause for the Query. |
Notes | Textual notes to describe the Query SDI for your reference. |
Query Arguments |
This element lets you resolve all Arguments you have made in the WHERE clause, as well as specify how you choose the Argument resolutions when displayed. For example, you can make a Query based on the User SDC, where sysuserid = [user]. Here, [user] is the single Argument. When you execute the Query, it first asks you to enter a value for the Argument. The Argument Definition lets you specify how the value of the Argument is entered. Click the up and down arrows to sort Arguments in the desired order.
Fields of the Query Arguments detail:
Field | Description | ||||||||||||||||
Argument | Identifier for the Argument (for recognition by the Query). | ||||||||||||||||
title | Name displayed to identify the Argument (for recognition by the user). | ||||||||||||||||
Mandatory | When checked, the argument is mandatory. This field maps
to the QueryArg.MandatoryFlag column. In an SDI List page, the Search Bar
(rendered by the advancedsearch
Element) will show these mandatory Arguments with a yellow background
as shown below. If a User submits a Query without filling in a mandatory
field, an alert dialog notifies the User.
|
||||||||||||||||
Arg Into | Variable holding Argument results. | ||||||||||||||||
Arg Type | Determines how the value of the Argument is entered into
the Query when the Query executes. Any type displayed in the Query Maintenance
Page but not listed below is not recommended for use at this time.
|
||||||||||||||||
Use Editor style
Editor style |
Determines if an Editor style is used to display the arguments and, if so, allow selection of an Editor style. | ||||||||||||||||
Reference Type | If the Arg Type is a RefType, choose the Reference Type. | ||||||||||||||||
Arg From SDC | If the Arg Type is an SDC, choose the SDC. | ||||||||||||||||
Lookup URL | URL for the page used to choose the Argument value. | ||||||||||||||||
Arg From SQL | If the Arg Type is SQL, enter the SQL statement. | ||||||||||||||||
Default Value | Default value for the Argument. | ||||||||||||||||
Allow Quotes | When checked, single quotes that are used as part of a query's criteria are automatically escaped. When unchecked, a user would need to do this themselves. Example: The data in my database has an apostrophe. Consider the contraction: o'clock. To handle this in a database query you would need to escape the apostrophe by adding another apostrophe. In Oracle, this would look something like this: SELECT 'o''clock' AS quoted_string FROM DUAL Therefore, in LabVantage, a user who is prompted for a value for this argument would need to type it like this: o''clock If the Allow Quotes option is ticked, the user can supply the value, o'clock, and LabVantage witll escape the apostrophe automatically. On a per-Argument basis, this overrides the global setting in System Configuration. Unlike the global setting (which supports only Oracle), this works with both Oracle and MS SQL Server DBMS. This sets the allowquotes flag in the table containing the argument, e.g., reportparam.allowquotesflag. |
About Arguments |
In the Query Maintenance page, you can specify up to twelve arguments (also referred to in LabVantage as "parameters").
When using these LabVantage Java Public API methods in sapphire.accessor, you also specify up to twelve arguments:
• | QueryProcessor.getKeyid1List(
String sdcid, String queryid ) Use this when there are no Arguments (parameters). |
• | QueryProcessor.getKeyid1List( String sdcid, String queryid, String [] params ) |
• | DAMProcessor.createRSetQ( String sdcid, String queryid, String[] params ) |
Multiple arguments can be displayed in an SDI List page Search Bar (rendered by the advancedsearch Element).
Test the Query |
This button does not test the Query under actual conditions. It performs a syntax check and determines if LabVantage can interpret the Query. For example, a Query that seems to function when tested with this button may not run in Data Entry (see Returning Text from a Calculation in the topic Concepts of Transformations and Calculations for an example of a Query that tests OK but fails in Data Entry). As an example, special variables such as [%currentuser%] will act like an argument when tested, but will return the requested value when the Query runs.
Example of Cascaded Arguments |
The following example shows how you can use Cascaded Arguments, which use the resolution of one Argument to resolve another Argument. All Queries and Arguments must follow SQL syntax rules of your DBMS. The following examples use Oracle syntax.
Purpose of Example |
In a List Page, list all SDIs that have been given a qualitative condition (Good, Bad, or Ugly). Add the capability to list only the SDIs that are applicable to a specific Project that is assigned to a specific Project Manager. In this case, the SDIs are special laboratory samples in a User SDC called NewSample.
This example builds the data structure shown below.
NewSample SDC | |||||||
SDI | SampleCondition | Project |
![]() |
Project SDC | |||
Sample-001 | Good | Project_A | SDI | ProjectManager |
![]() |
User SDC | |
Sample-002 | Good | Project_B | Project_A | User_1 | SDI | ||
Sample-003 | Bad | Project_C | Project_B | User_2 | User_1 | ||
User_2 |
Creating the Data Structure |
1. | Add the SampleCondition Reference Type: |
a. | Add a Reference Type called SampleCondition. | |
b. | Add the Reference Values Good, Bad, and Ugly. These Reference Values will specify the qualitative condition of the NewSample SDIs. |
2. | Add User SDIs : |
To the User SDC, add the SDIs User_1 and User_2. These will be the Project Managers. |
3. | Add Columns and SDIs to the Project SDC: |
a. | To the Project SDC, add the column projectmanager. Use an SDC Link to link this column to the User SDC. The projectmanager column identifies the Project Manager assigned to each Project SDI. | |||||||
b. | To the Project SDC, add the SDIs Project_A and Project_B. | |||||||
c. | Add the column projectmanager to the Project Maintenance Page. | |||||||
d. | In the Project Maintenance Page, assign the following values to the specified
SDIs:
|
Add the NewSample SDC, then Add Columns and SDIs
1. | Add a User SDC called NewSample, which will contain SDIs that are special laboratory samples. | ||||||||||||
2. | Add the column project and link it to the Project SDC, using an SDC Link. This column identifies the Project applicable to each NewSample SDI. | ||||||||||||
3. | Add the column samplecondition and link it to the SampleCondition Reference Type, using a Reference Link. This column will contain the Reference Values (Good, Bad, or Ugly) that identify the qualitative condition of each NewSample SDI. | ||||||||||||
4. | To the NewSample SDC, add the SDIs Sample_001, Sample_002, and Sample_003. | ||||||||||||
5. | Using the Form Painter Page, add the columns project and samplecondition to the NewSample Maintenance Page. | ||||||||||||
6. | In the NewSample Maintenance Page, assign the following values to the
specified SDIs:
|
Defining the Query |
We will call our example Query GoodSamples because we want to list u_newsample SDIs that have been classified as "Good". The GoodSamples Query:
SELECT * FROM u_newsample WHERE project = '[proj]' AND samplecondition = '[cond]'
This Query retrieves, from the NewSample SDC, all SDIs relevant to a Project and a Sample Condition. Note that you must specify the actual table name for the SDC, u_newsample, which is prefaced by the u_ denoting a User SDC.
To resolve the arguments in the WHERE clause (Project [proj] and Sample Condition [cond]), you must define each. The example below shows how each Argument resolves the Query.
Query | SELECT *
FROM u_newsample WHERE project = '[proj]' AND samplecondition = '[cond]' |
||||||||||||
Arguments to Resolve Query |
|
Note that the Project [proj] argument can be resolved only after definition of a Project Manager [pm]. In other words, the Project Manager is required input for resolution ot the Project argument. You must always define arguments as they will be executed by the Query. The schematic above shows this "bottom-up" approach, analogous to "nested" instructions that must be carried out in sequence. The table below shows the order in which you would define the Arguments in the Query Maintenance Page.
Argument | Arg Into | Arg Type | Reference Type | Arg From SDC | Arg From SQL |
Project Manager | [pm] | SDC (drop down) | User | ||
Projects | [proj] | SQL (drop down) | SELECT projectid, projectdesc FROM project WHERE projectmanager ='[pm]' |
||
Sample Condition | [cond] | RefType (drop down) | SampleCondition |
Executing the Query |
The illustration below shows how the Query behaves when executed in the u_newsamples List Page. Using the List Page Properties, the Filter Bar is configured to contain Queries. Clicking the Good Samples Query opens drop lists in a split-frame, allowing you to successively resolve each argument as shown.
Examples of Collective Arguments |
Creating a Query that shows all Information in an SDC |
1. | From the Based On drop-list, choose the SDC from which you want to retrieve Values. |
2. | You can now view the SDC information by clicking Test Query, which opens a window showing the contents of all columns in the SDC. |
Creating a Query that shows the contents of a Single Column in an SDC |
1. | From the Based On drop-list, choose the SDC from which you want to retrieve Values. |
2. | In the Where field, enter the SQL WHERE clause that specifies retrieval of a single table column. |
When you specify calendar dates in Queries made to an Oracle database, you must use the to_date function. For example, to write a Query that retrieves all SDIs created between a Start Date and an End Date, use the following syntax in the WHERE clause of the SQL statement:
WHERE createdt > to_date('[%adjstartdate%]', 'mm/dd/yy hh24:mi:ss' ) and createdt < to_date('[%adjenddate%]', 'mm/dd/yy hh24:mi:ss' )
For [startdate] and [enddate], set the Type (Argument Definition) to AbsrelDt.
Using Special Variables |
|
WHERE createby='[%currentuser%]'
This Query retrieves all Samples created by the current User.
Additional Union Clauses |
When "Union Query" is checked on the Query Form and the page is saved, the "Additional Union Clauses" detail tab is rendered to manage Queries that include a union between two separate from and where clauses. The primary query is the first query in the union. The "From Clause" and "Where Clause" in this detail are added to create the overall union query.
![]() |
This is an alternative to using an OR in the where clause, as the performance of a UNION is superior to that of an OR. This is particularly effective in queries requiring different additional criteria based on the value of a given column. For example:
Example OR: | select s_sampleid from s_sample where sampletypeid = 'raw' or sampletypeid = 'finished'; |
Example UNION: | select s_sampleid from s_sample where sampletypeid = 'raw' union select s_sampleid from s_sample where sampletypeid = 'finished'; |
The examples below show two OOB Queries from LabVantage 8.2.x that have modified using unions for LabVantage 8.3.0:
LabVantage 8.2.x Query (using OR) | LabVantage 8.3.0 Query (using UNION) |
ByStudy
PRIMARY: FROM s_sample left outer join s_samples_study aux on aux.s_sampleid =
s_sample.s_sampleid |
ByStudyU
PRIMARY: FROM s_sample UNION: FROM s_sample,s_samples_study aux |
ByStudyStatus PRIMARY: FROM s_sample left outer join s_samples_study aux on aux.s_sampleid =
s_sample.s_sampleid |
ByStudyStatusU PRIMARY: FROM s_sample UNION: FROM s_sample,s_samples_study aux |