Join the Alteryx Community’s Maveryx Summer Cup event! Compete, network with others, and earn your gold through a series of challenges from July 24th to August 11th. Learn more about the event here.

Alteryx Designer Desktop Discussions

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

Execute a large list of queries and union results together

dataguy4life
5 - Atom

I'm trying to make a file with 3 non-null samples from every field in a database. I have a long list of queries that would generate the results, and I am hoping I can automate by having Alteryx execute the large list of queries and union the results together. Below are an example of the input and output I'm hoping for.

 

I already have my input (list of queries), so that's not an issue. I can successfully execute one query at a time. How can I execute in bulk and create the output?

 

INPUT:

QueryIDQuery
1SELECT [Field1] as value FROM [SCHEMA].[Table1] WHERE [Table1].[Field1] is not null limit 3
2SELECT [Field2] as value FROM [SCHEMA].[Table1] WHERE [Table1].[Field2] is not null limit 3
3SELECT [Field3] as value FROM [SCHEMA].[Table2] WHERE [Table2].[Field3] is not null limit 3
4SELECT [Field4] as value FROM [SCHEMA].[Table2] WHERE [Table2].[Field4] is not null limit 3
......
10000SELECT [FIELD10000] as value FROM [SCHEMA].[Table95] WHERE [Table95].[Field10000] is not null limit 3

 

 

OUTPUT:

QueryIDValueIDValue
11A
12B
13C
2111/1/22
2211/2/22
2311/3/22
31John
32Vanessa
33Mary
4197489
4283739
4328956
.........
100003ABC
5 REPLIES 5
DataNath
17 - Castor

Hey @dataguy4life, I notice that you've used the 'Batch Macro' tag in your post, which is exactly what I'd suggest here. You'd feed in your list of queries to the control parameter, which will update the query that sits in the Input tool within the macro itself. What I would say is that you'll need to force the data type of the [Value] data into a uniform type (String: Forced) with a Select tool before the macro output so that when the batch macro has ran, the results can be unioned and there's no schema error from the varying data types coming through from the queries (dates/integers/strings etc).

 

https://community.alteryx.com/t5/Alteryx-Designer-Knowledge-Base/Getting-Started-with-Batch-Macros/t...

gabrielvilella
14 - Magnetar

I believe a batch macro could help you on this. The macro will run one time for each query and then all results will be on a single table. 

Felipe_Ribeir0
16 - Nebula

Hi @dataguy4life 

 

I was able to replicate your situation here for SQL Server using the attached workflow.

 

Felipe_Ribeir0_0-1667405247482.png

1)Just configure the input of queries correctly

Felipe_Ribeir0_1-1667405302489.png

 

2)Inside the macro, change the input file connecting it to a valid server/database/table

 

Felipe_Ribeir0_3-1667405378432.png

 

3)Inside the update tool, configure it to replace the query of the item 2.

Felipe_Ribeir0_2-1667405350746.png

 

And it will work properly for sure.

 

dataguy4life
5 - Atom

This worked!!! Thank you so much!!!!!

 

 

dataguy4life
5 - Atom

Hi DataNath, this was a really helpful tip about the data type. Thank you so much!!!

Labels