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
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

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

MPA Licensing.jpg

Ask your licensing questions at the Power Automate AMA!

Join Priya Kodukula and the licensing team, super users and MVPs to find answers to your questions on Power Automate licensing.

Users online (3,138)