How To Use The 'in' Statement in Parameterized SQL Queries
How can I successfully use the 'in' statement with a parameterized SQL query? Our goal is to do something like select * from TableName where FieldName in (@variable). In this scenario @variable would be a list of strings instead of a single string.
Comments
-
There may be several ways to do this, depending on what you are using as your SQL database. Different databases will use a different wildcard character. For example, Oracle will use a colon (:) character, and snowflake will use a question mark (?). Some also support lists as inputs to parameterized queries, while others do not.
If you are using a database that supports lists, this can be done by editing your parameter (either "add", or the pencil icon next to an existing parameter under the "Input Parameters" section of the database integration popup), and selecting "Is List".
If you are using a database that does not support lists, this can still be done, but it does require a bit more configuration. Within your Decisions flow, you will need to convert your list of strings into a single string separated by a comma, in a Join Strings step. Use the output of this as the input of your parameter, adjust your query to split the string based on comma. The resulting query would look something like this:
SELECT * FROM table_name WHERE field_name in (SELECT value FROM STRING_SPLIT(@variable,','));
- Parameterized Queries: https://documentation.decisions.com/docs/parameterized-queries
Howdy, Stranger!
Categories
- 4.2K All Categories
- 67 General
- 11 Training
- 202 Installation / Setup
- 1.1K Flows
- 106 Rules
- 262 Administration
- 212 Portal
- 490 General Q & A
- 695 Forms
- 333 Reports
- 3 Designer Extensions
- 47 Example Flows
- 52 CSS Examples
- 1 Diagram Tile
- 7 Javascript Controls
- 179 Pages
- 5 Process Mining
- New Features
- 179 Datastructures
- 69 Repository
- 221 Integrations
- 28 Multi-Tenant
- 27 SDK
- 78 Modules
- 56 Settings
- 25 Active Directory
- 12 Version 7
- 35 Version 8
- 83 Lunch And Learn Questions