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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / How to deal with SQL Q...
Power Automate
Unanswered

How to deal with SQL Query when there are no results

(0) ShareShare
ReportReport
Posted on by 119

I have a need to email a weekly list of new items added to a table in SQL. I have written a query in flow but some weeks there are no new items, which causes the flow the fail.

 

How can I add a condition which sends the query results if there are rows returned, but send a different email  when the query result is null? I have tried length(body('Get_items')?['value']) greater than 0, but this fails when the query is null.

Categories:
  • RezaDorrani Profile Picture
    12,145 on at

    Hi @Graham 

     

    just tried with length(body('Get_items')?['value'])  and it worked 

     

    can you post screenshot of output from sql query when flow fails

  • v-bacao-msft Profile Picture
    Microsoft Employee on at

     

    Hi @Graham ,

     

    Could you provide screenshot of Flow configuration?

    If you are using Get rows action, please refer to the following expression:

    152.PNG

    In the length() function we need to configure the name of the actual action and use an underscore instead of space.

     

    Best Regards,

  • Graham Profile Picture
    119 on at

    This is the error from flow;

    Flow1.png

     

    This is the content;

    Flow2.png

    The formula is: 

    length(body('Get_List_of_Funds_Requests')?['value'])
     
     
  • v-bacao-msft Profile Picture
    Microsoft Employee on at

     

    Hi @Graham ,

     

    Have you seen the execution results of Get List of Funds Requests action?

     

    Best Regards,

  • Graham Profile Picture
    119 on at

    The query results in no records being fetched, hence the 'Null'. That is what I expected, as this relates to a weekly flow that looks for records added during the previous weeks. Some weeks there will be no new records, so I need flow to do something else in the knowledge there are no results.

  • v-bacao-msft Profile Picture
    Microsoft Employee on at

     

    Hi @Graham ,

     

    Could you provide a screenshot of Get List of Funds Requests action?

    We need to provide a viable expression based on the specific execution results.

     

    Best Regards,

  • Graham Profile Picture
    119 on at

    Hi,

     

    It is a simple SELECT query - I would rather not share the exact contents, for obvious reasons, but here is something similar;

     

    SELECT

    dbo.Incidents.IncidentID,

    dbo.Incidents.Reference,

    dbo.Funds.RequestID,

    dbo.Funds.RequestAmount,

    FORMAT(dbo.Funds.RequestDate, 'dd/MM/yyyy', 'en-us') as FundsReqDate

    FROM

    dbo.Incidents INNER JOIN dbo.Funds ON dbo.Incidents.IncidentID=dbo.Funds.IncidentNumber INNER JOIN dbo.Timelapse ON dbo.Funds.RequestDate>dbo.Timelapse.Weekago

     

    Timelapse is a 'View' on SQL server and calculates the date of -7 days - It's something we use for a lot of queries.

     

    So when no new records are found for the last 7 days, it returns 'Null' to Flow, which breaks the condition statement.

     

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 289

#2
11manish Profile Picture

11manish 288 Super User 2026 Season 2

#3
Henil Profile Picture

Henil 125

Last 30 days Overall leaderboard