SQL Query with Parameters

LabKey Support Forum
SQL Query with Parameters marcia hon  2018-02-23 10:32
Status: Closed
 
Hello,

I wish to create an SQL query that uses parameters.

These parameters I would like to use in the "IN" command.

For example:

WHERE values IN parameters

How do I do this? If I enter something like this in parameters it does not work: value1, value2, value3

Thanks,
Marcia
 
 
marcia hon responded:  2018-02-23 11:33
Also, what version of SQL is used in Labkey?

Is it Oracle? DB2?

Thanks
 
marcia hon responded:  2018-02-26 05:48
I have a parameter in my SQL script.

I would like this parameter to be used in the query with an "IN" command.

How do I enter data? Should it be "abc, dge, fec"?

And how do I parse this in the "IN" command?
 
marcia hon responded:  2018-02-27 08:22
We are thinking of a workaround...

Create the query...

and then,

use Gridview to filter the query...


Thanks!
 
Jon (LabKey DevOps) responded:  2018-03-09 14:43
Hi Marcia,

Have you taken the time to review our robust Support Documentation?

https://www.labkey.org/Documentation/wiki-page.view?name=default

Many of your questions can be answered in our docs and we even have videos to help you understand how to both use LabKey and understand the functionality:

https://www.labkey.org/Documentation/wiki-page.view?name=videos

For future, please do your best to consult our fantastic docs first before posting to the Community Forums.


Regarding your question about which version of SQL is used with LabKey, only PostgreSQL and Microsoft SQL Server are supported for use with the LabKey platform:

https://www.labkey.org/Documentation/wiki-page.view?name=supported

We can interface with other databases as an external datasource and have it appear as an External Schema on a read-only basis:

https://www.labkey.org/Documentation/wiki-page.view?name=externalSchemas

The LabKey SQL dialect itself is a pretty universal SQL dialect that does leverage some database-specific functions depending on what DB you're running off of:

https://www.labkey.org/Documentation/wiki-page.view?name=labkeysql

Regarding using the IN operator with Parameters, this is not possible since the Parameterization doesn't treat multiple values within the field as separate fields, but as one single value.

For example, putting in "abc, dge, fec" in a Parameterized field wouldn't treat it as three separate values, but rather one whole value. So it would treat it like:

WHERE fieldname IN ("abc, dge, fec")

rather than

WHERE fieldname IN ("abc", "dge", "fec")

So in order to get the desired result you want, you would need to do your filtering via your grid after the results render since the filter on the grid does allow you to filter in a variety of ways, such as "Equals One Of", "Contains One Of", and more:

https://www.labkey.org/Documentation/wiki-page.view?name=filteringExpressions
https://www.labkey.org/Documentation/wiki-page.view?name=filteringData

Regards,

Jon