如何验证 Azure 逻辑应用程序中 "Execute a SQL query" 操作的输出

How to validate the output of "Execute a SQL query" action in Azure Logic App

我通过添加 执行 SQL 查询 (V2) 操作创建了一个 Azure 逻辑应用程序。在 Execute a SQL 查询操作中,我使用了以下查询来获取特定列数据。

select XXXX from [dbo].[XXXX] where XXXX=@{triggerBody()?['XXXX']?['XXXX']}

我正在使用以下表达式获取列数据:

body('Execute_a_SQL_query_(V2)')?['resultsets']?['Table1'][0][<'Name of table column'>]

但对于某些场景执行SQL查询操作returns以下响应:

{
  "ResultSets": {},
  "OutputParameters": {}
}

每当 执行 SQL 查询 操作 returns 空响应时,我就会收到以下错误:

InvalidTemplate. Unable to process template language expressions in action 'Set_variable' inputs at line '0' and column '0': 'The template language expression 'int(body('Execute_a_SQL_query_(V2)')?['resultsets']?['Table1'][0]['XXXX'])' cannot be evaluated because property '0' cannot be selected

那么,谁能建议我如何验证“ResultSets”对象是否为空?

您可以使用下面的表达式条件来评估ResultSets是否是empty然后继续下一步。

equals(string(outputs('Execute_a_SQL_query_(V2)')?['body']['ResultSets']),'{}')

示例:

如果是true,则表示它是空集。