The following SQL query defines two parameters, MinTemp and MinWeight:
PARAMETERS
(
MinTemp DECIMAL DEFAULT 37,
MinWeight DECIMAL DEFAULT 90
)
SELECT PhysicalExam.ParticipantId,
PhysicalExam.date,
PhysicalExam.weight_kg,
PhysicalExam.temperature_C
FROM PhysicalExam
WHERE temperature_C >= MinTemp and weight_kg >= MinWeight
By default, parameterized queries are hidden in the Schema Browser. Select Show Hidden Schemas and Queries to view. Go to the Schema Browser, and look in the far lower left. For details, see SQL Query Browser.
To pass a parameter value to the query on the URL use the syntax:
&query.param.PARAMETER_NAME=VALUE
For example, the following URL sets the parameter '_testid' to 'Iron'. Click below to execute the query.
You can pass in parameter values via the JavaScript API, as shown below:
<div id="div1"></div>
<script type="text/javascript">
function init() {
var qwp1 = new LABKEY.QueryWebPart({
renderTo: 'div1',
title: "Parameterized Query Example",
schemaName: 'study',
queryName: 'ParameterizedQuery',
parameters: {'MinTemp': '36', 'MinWeight': '90'}
});
}
</script>
The parameters are written into the request URL as follows:
query.param.MinTemp=36&query.param.MinWeight=90
You can also pass in values using a built-in user interface. When you view a parameterized query in LabKey Server, a form is automatically generated, where you can enter values for each parameter.
You can also use parameterized SQL queries as the source queries for ETLs. Pass parameter values from the ETL into the source query from inside the ETL's config XML file. For details see ETL: Examples.
previousnext |
expand allcollapse all |