Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Loop through table to create dynamic SQL query

cutehappybear
7 - Meteor

Hello everyone,

 

I have a table that goes like this:

123

456

789

(...)

 

I then want to connect to a DB table and perform a SELECT statement, using all the values from that table, for example:

SELECT * FROM db.Table WHERE Number = '123' and Number = '456' and Number = '789'

 

Any suggestion on how to do this? Thank you!

 

2 REPLIES 2
atcodedog05
22 - Nova
22 - Nova

Hi @cutehappybear 

 

Assuming your SQL supports IN function like

SELECT * FROM db.Table WHERE Number IN ('123','456','789')

 

. You can convert the to like below

atcodedog05_0-1641288779924.png

 

You can dynamic input tool to modify the part of the query and pass the values

 

Refer this video from 8:50th Min https://www.youtube.com/watch?v=ELfKYatOJZM 

 

Hope this helps : )

kelvin_law1
9 - Comet

Hi @cutehappybear,

 

You can use a Summarize Tool to concatenate all the values in your table first.  This is how you can configure it:

kelvinlaw_0-1641288800620.png

Afterwards you can use a Dynamic Input Tool to connect to your SQL database with a query by pressing the Edit button similar to the following:

kelvinlaw_1-1641289437512.png

Then you can select the Modify SQL Query option and choose Replace a Specific String or SQL: Update WHERE Clause to make this query dynamic

kelvinlaw_2-1641289483040.png

kelvinlaw_3-1641289705232.png

 

Now you should able to get the data that you want after running the workflow.

Hope it helps!!

 

Labels