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
Super User
Super User

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
Super User
Super User

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

Helpful resources

Announcements
MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

Top Solution Authors
Top Kudoed Authors
Users online (67,976)