Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

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

Leverage select tool output to replace placeholder string within SQL query input?

GreysonP
5 - Atom

Hello all. First time posting here.

 

I have an Alteryx workflow with two inputs:

1. Excel file containing a list of dates

2. ODBC Input with SQL Query

 

I am attempting to create a workflow that first, identifies the minimum and maximum dates within the Excel file. Thereafter, I am looking to leverage those two date values to replace two date placeholders within the SQL query before running.

 

The workflow currently identifies the two date values in the following format: (as outputs of a select tool)

StartDate         EndDate

2018-02-02      2019-02-03

 

The SQL query looks like this: (looking to replace 'StartDate' and 'EndDate' with outputs of previous Select tool)

Select *

From 'dummytable'

WHERE DateField >= 'StartDate'

AND DateField <= 'EndDate'

 

Does anyone have a solution for this? Thank you very much in advance.

3 REPLIES 3
geraldo
13 - Pulsar

@GreysonP 

 

An  workflow example

 

Insert the macro after the select tool and place the container with input data in the macro.

geraldo_0-1683745783079.png

 

 

braveraj
11 - Bolide

Hi GreysonP

 

Pretty simple solution for your issue. You'll want to have that data set with the start and end date feed into a dynamic input tool where you have your custom SQL script. In the modify SQL Query part, you'll add 2 separate "SQL: Update WHERE Clause" and just select the string of text to replace in both conditions. Just make sure you're consistent with the string you want to replace. In my workflows I will typically put a data value of '9999-12-31' or something like that to always replace in the dynamic input tool.

 

Happy solving!

 

braveraj_0-1683745593439.png

 

GreysonP
5 - Atom

Thank you for your help! This worked. Much appreciated.

Labels