Share via


How to check sql execute query data is null in logic app expression?

Question

Thursday, July 4, 2019 7:05 AM

In logic app after executing SQL_Exceute_Query I got result like below -

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

How can I check ResultSets do not have any data using expression?

I tried like body('Exceute_a_sql_query')?['ResultSets'] is not equal to '{}' in condition connector but not working for me.

If body('Exceute_a_sql_query')?['ResultSets'] having data go to if otherwise go to else

SE

All replies (4)

Thursday, July 4, 2019 9:46 AM

You can use empty() function to check if the value is empty. https://docs.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#empty It returns Boolean value. empty(body('Exceute_a_sql_query')?['ResultSets']) OR, you can also compare with null value equals(body('Exceute_a_sql_query')?['ResultSets'],null)

Shreedivya


Thursday, July 4, 2019 9:55 AM | 1 vote

Hello Anshu,

You use length() function if the result set is an empty array.

"expression": {
                   "and": [
                            {
                             "equals": [
                                 "@length(body('Exceute_a_sql_query')?['ResultSets'])",
                                  0
                               ]
                            }
                        ]
                    },

Thursday, October 31, 2019 7:02 PM

I tried this and it tells me I can't use the 'length' function on an object.

equals(length(body('Execute_a_SQL_query_(V2)')?['resultsets']))

InvalidTemplate. Unable to process template language expressions for action 'Condition_2' at line '1' and column '2808': 'The template language function 'length' expects its parameter to be an array or a string. The provided value is of type 'Object'. Please see https://aka.ms/logicexpressions#length for usage details.'.


Thursday, October 31, 2019 7:21 PM

I used empty on the object and got it to work:

empty(body('Execute_a_SQL_query_(V2)')?['resultsets'])