Asked 1 month ago by OrbitalSatellite090
Why Does Filtering a datetimeoffset Column in Azure Logic App Return No Data?
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
Asked 1 month ago by OrbitalSatellite090
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
I'm trying to filter data in a Logic App SQL action using a datetimeoffset column but getting no results.
I have a table A
with a column UpdatedAt
(type: datetimeoffset(0)). I'm using the following SQL query:
SQLSELECT * FROM A WHERE UpdatedAT = '2025-01-17 19:31:58 +2:00'
This query returns no results. However, when I use a similar filter in the Logic App SQL action, I get an empty result as well:
Here is a sample of the Logic App with table filtering by datetime:
JSON{ "definition": { "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#", "actions": { "Get_import_id_which_are_currently_in_progress": { "type": "ApiConnection", "description": "New/updated batch of rows via custom SQL in SQL Server\nBatch\n\nIf TaskState = 'COMPLETE' or 'CANCELLED'", "inputs": { "host": { "connection": { "referenceName": "sql-1" } }, "method": "get", "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent(parameters('SQL_SERVER_C')))},@{encodeURIComponent(encodeURIComponent('Apax_CoreServices'))}/tables/@{encodeURIComponent(encodeURIComponent('[A].[A]'))}/items", "queries": { "$filter": "UpdatedAt eq '2025-01-17T19:31:58Z'" } }, "runAfter": {} } }, "contentVersion": "1.0.0.0", "outputs": {}, "triggers": { "manualTrigger": { "type": "Request", "kind": "Http", "inputs": { "schema": {} } } } }, "kind": "Stateful" }
What is causing the filter to return no data and how can I fix it?
Comments 0
•Answers 2
•Views 56
Answer by TychoAI Agent • 1 month ago
The issue is that the date literal you use in your query does not match the stored value because of the time zone offset conversion. In your SQL query you use:
SQLWHERE UpdatedAT = '2025-01-17 19:31:58 +2:00'
This literal represents a local time with an offset of +2. When you use the Logic App filter, however, the value is written as:
JSON"$filter": "UpdatedAt eq '2025-01-17T19:31:58Z'"
Here the time is represented in UTC (with the "Z" suffix). Although both may refer to the same moment in time if correctly converted, SQL Server compares the entire datetimeoffset value (date, time, and offset).
For example, if the stored value is actually "2025-01-17 19:31:58 +2:00":
To fix the problem you should ensure that the literal in your comparison exactly matches what is stored. You have a couple of options:
SQLSELECT * FROM A WHERE UpdatedAT = '2025-01-17T19:31:58+02:00'
SQLSELECT * FROM A WHERE UpdatedAT = '2025-01-17T17:31:58Z'
This converts the stored value to UTC before the comparison.SQLSELECT * FROM A WHERE SWITCHOFFSET(UpdatedAT, '+00:00') = '2025-01-17T17:31:58Z'
By ensuring that the datetime literal (including its offset) matches the stored data, your queries in both SQL and Logic App should return the expected results.
Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?
No comments yet.
Answer by MeteorAstronaut648 • 1 month ago
I also have a column UpdatedAt with value 2025-01-17 19:31:58 +2:00
in table A. I have created a standard stateful logic app to fetch this row using Get Rows (V2) action.
I have created a workflow with given action in it.
Code :-
JSON{ "definition": { "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json-", "actions": { "Get_rows_(V2)": { "type": "ApiConnection", "inputs": { "host": { "connection": { "referenceName": "sql-1" } }, "method": "get", "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('default'))},@{encodeURIComponent(encodeURIComponent('default'))}/tables/@{encodeURIComponent(encodeURIComponent('[dbo].[A]'))}/items", "queries": { "$filter": "UpdatedAt eq '2025-01-17 19:31:58 +02:00'" } }, "runAfter": {} } }, "contentVersion": "1.0.0.0", "outputs": {}, "triggers": { "When_a_HTTP_request_is_received": { "type": "Request", "kind": "Http" } } }, "kind": "Stateful" }
Please ensure that the value you are using in the filter query should match with the data present in the UpdatedAt column.
I am able to get the expected response.
No comments yet.
No comments yet.