web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
Answered

Need help writing a condition for a SQL Stored Procedure

(0) ShareShare
ReportReport
Posted on by

This is probably incredibly easy, but I am struggling.  I want to write a scheduled flow that calls a stored procedure from SQL and if the Stored Procedure returns results, then send an email with an html table of those results.  If no results are returned, then do nothing.

The part I am having trouble with is choosing a value for the condition.  I want it to just be "is not null" but that isn't a choice.  I'm confused by all the different values, parameters, dynamic content, and expressions and am not sure how to write what I want.  I've tried length is greater than 0 but that failed and I feel like I'm just poking around in the dark.

Please help! Thanks!

 
I have the same question (0)
  • fchopo Profile Picture
    8,001 Moderator on at
    Re: Need help writing a condition for a SQL Stored Procedure

    Hello @Anonymous 

    Please, have a look at this solution by @v-xida-msft : https://powerusers.microsoft.com/t5/Building-Flows/Checking-for-empty-stored-procedure-result/td-p/63791

    Basically, the condition should be the following:

    @not(empty(body('execute_stored_procedure')?['resultsets']))

    Hope it helps!

    Ferran

  • Community Power Platform Member Profile Picture
    on at
    Re: Need help writing a condition for a SQL Stored Procedure

    Thank you for your quick reply, and pointing me to the other post which I clearly missed when I searched.  But my Conditions step looks different from that poster.  And although I added only one "@" it seems to have added more when I saved.  When I tested the flow it ran successfully but did not generate an email, even though I know the stored procedure as it is written is returning results.Screen Shot 2020-05-22 at 12.35.18 PM.png

  • fchopo Profile Picture
    8,001 Moderator on at
    Re: Need help writing a condition for a SQL Stored Procedure

    Hello @Anonymous 

    Try the following expression:

     

    flow.png

     

    Using "dynamic expressions" on both sides of the condition.

    Hope it helps!

    Ferran

  • Community Power Platform Member Profile Picture
    on at
    Re: Need help writing a condition for a SQL Stored Procedure

    Screen Shot 2020-05-22 at 1.10.45 PM.png

    I think I got the text the same as you, but I'm getting this error now; The template validation failed: 'The action(s) 'execute_stored_procedure' referenced by 'inputs' in action 'Condition' are not defined in the template.'.

  • Verified answer
    fchopo Profile Picture
    8,001 Moderator on at
    Re: Need help writing a condition for a SQL Stored Procedure

    Hello @Anonymous 

    Please, rename the action "execute stored procedure (v2)" by "execute stored procedure" or maybe changing the expression:

    not(empty(body('execute_stored_procedure_(v2)')?['resultsets']))

    Hope it helps!
    Ferran 

  • Community Power Platform Member Profile Picture
    on at
    Re: Need help writing a condition for a SQL Stored Procedure

    That did it!  Thank you so very much!  Have a wonderful weekend!

  • Community Power Platform Member Profile Picture
    on at
    Re: Need help writing a condition for a SQL Stored Procedure

    Actually.. I didn't test enough before saying it resolved it.... it seems as though even when the PROC isn't returning any result, it is still firing an email that has no content.  So I need to tweak it a little more.  But I do very much appreciate you getting me as far as you did @fchopo 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 722 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 461 Moderator

#3
developerAJ Profile Picture

developerAJ 283

Last 30 days Overall leaderboard