cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
rth
Regular Visitor

SQL execute procedure V2- How to use dynamic result sets within "apply to each" loop

Hi all,

I'm calling a dynamic procedure from Flow with ExecuteStoredProcedure V2

The procedure is generating a dynamic query.

Because of that, the dynamic parameters of PA don't work for me.

 

Still, how can I iterate now through this result set. My column headers are static and known.

 

 

create procedure GetDynamicValue
@TableName varchar(50),
@ColumnName varchar(50)
as
begin
DECLARE	@sqlStatement NVARCHAR(4000)
  
set @sqlStatement = N'SELECT CT.Id as Id,'+ @ColumnName +' as Value FROM '+@TableName+''  
 exec sp_executesql @sqlStatement
end

 

1 ACCEPTED SOLUTION

Accepted Solutions
Amanthaper
Responsive Resident
Responsive Resident

Hi,

I've recently done something similar, please take a look at the example below using the following steps:

 

  1. Using the SQL execute procedure V2 with params exposes params in action for input.
  2. We monitor the "Resultsets" from the executed SP to smartly do things downstream (optional).
  3. Parse the executed SP "body" using the Parse JSON action. This will expose "Table1".
  4. Use "Table1" in the Apply to each action.

PA_UG_SP.pngPA_UG_SP2.png

 

Hope this helps,

Aman T.

 

View solution in original post

1 REPLY 1
Amanthaper
Responsive Resident
Responsive Resident

Hi,

I've recently done something similar, please take a look at the example below using the following steps:

 

  1. Using the SQL execute procedure V2 with params exposes params in action for input.
  2. We monitor the "Resultsets" from the executed SP to smartly do things downstream (optional).
  3. Parse the executed SP "body" using the Parse JSON action. This will expose "Table1".
  4. Use "Table1" in the Apply to each action.

PA_UG_SP.pngPA_UG_SP2.png

 

Hope this helps,

Aman T.

 

Helpful resources

Announcements
 WHAT’S NEXT AT MICROSOFT IGNITE 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Register for a Free Workshop.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Users online (1,445)