You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Logic App:SQL查询空结果集条件检查返回True的异常问题

Troubleshooting Empty Result Set Condition Mismatch in Azure Logic Apps

Alright, let's dig into why your Azure Logic App's condition is misbehaving when the SQL query returns an empty result set. I've run into similar head-scratchers before, so here are the most common culprits and fixes:

  • You're checking the wrong JSON path in your condition
    The SQL Server action in Logic Apps nests results under resultsets > Table1 (or your custom result set name). If you're checking the root body of the action instead of the actual rows array, you might be evaluating a non-empty metadata object instead of the empty results.
    Fix: Open the "Run History" of your Logic App, navigate to the "Execute SQL query" step, and look at the raw output. Grab the exact path to your rows (e.g., body('Execute_SQL_query')?['resultsets']?['Table1']). Update your condition to target this path—use empty(body('Execute_SQL_query')?['resultsets']?['Table1']) to check if rows are empty.

  • Null vs. Empty Array confusion
    Sometimes, when the query returns no rows, the SQL action returns null instead of an empty array []. Logic Apps' "is not empty" condition treats null as "not empty" (since it’s a non-empty value type), which is why you’re seeing True when you expect False.
    Fix: Use coalesce() to convert null to an empty array before checking. Example: empty(coalesce(body('Execute_SQL_query')?['resultsets']?['Table1'], [])). This handles both null and empty array cases correctly.

  • Implicit type conversion messing up evaluations
    Logic Apps can auto-convert values in conditions unexpectedly. A simple "is not empty" check on a null or non-array value might not behave as you’d expect.
    Fix: Explicitly check the length of the results array. Use length(coalesce(body('Execute_SQL_query')?['resultsets']?['Table1'], [])) and compare it to 0. If the length equals 0, the result set is empty.

  • Stale run history or cached results
    It’s easy to accidentally look at an older run where the query returned results instead of the latest empty run.
    Fix: Open the most recent run with the unexpected condition result, go to the SQL query step, and inspect the "Outputs" tab. Copy the raw JSON to confirm exactly what data the Logic App is processing—this will eliminate any confusion about stale data.

  • The query returns metadata but no rows
    In some cases, even with no rows, the SQL action might return an object with metadata (like column names) but an empty rows array. If your condition checks the parent metadata object instead of the rows, it will think the result is non-empty.
    Fix: Double-check the raw output to identify the exact array containing your rows, and adjust your condition to target that specific array.

Pro tip: Always start by inspecting the raw output of your SQL query step. Seeing the exact JSON structure the Logic App is working with makes troubleshooting the condition logic way easier.

内容的提问来源于stack exchange,提问作者Fisqkuz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.27 21:17:51