cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
BrianH
Microsoft
Microsoft

How to handle no records returned from Execute a SQL Query (V2)?

My flow runs a query to get records from the database using Execute a SQL Query (V2). Then is enters into Apply to each loop. But sometimes the query will return no results (which is expected). I am currently getting the error below. How to I not go into the Apply to each loop if there are no records returned from the query?

 

The execution of template action 'Apply_to_each_2' failed: the result of the evaluation of 'foreach' expression '@body('Execute_a_SQL_query_(V2)')?['resultsets']?['Table1']' is of type 'Null'. The result must be a valid array.

1 ACCEPTED SOLUTION

Accepted Solutions
BrianH
Microsoft
Microsoft

I have found a workaround. I am checking if the table object is null using a "Condition"

 

 

Screenshot 2021-03-26 135235.jpg

View solution in original post

1 REPLY 1
BrianH
Microsoft
Microsoft

I have found a workaround. I am checking if the table object is null using a "Condition"

 

 

Screenshot 2021-03-26 135235.jpg

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.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (4,039)