Adding datetime as dynamic content to a query

Bakar, Cem 281 Reputation points
2021-04-09T13:02:01.443+00:00

This is my query
SELECT Id, ...
FROM Task
WHERE LastModifiedDate > @{activity('Lookup_SF_Task').output.firstRow.LastExtractRecordDate}

This is how LastExtractRecordDate is being pulled by a Look Up module.86304-screen-shot-2021-04-09-at-85531-am.png

This is the error I get
86322-screen-shot-2021-04-09-at-85812-am.png

No matter how I wrap/format/cast/convert the date it seems to find a way to complain..

Can anyone explain how to use dynamic content / parameters / syntax ?

Thank you.

Azure Databricks
Azure Databricks
An Apache Spark-based analytics platform optimized for Azure.
1,940 questions
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
9,609 questions
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
36,195 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,555 questions
0 comments No comments
{count} votes

Accepted answer
  1. Nasreen Akter 10,751 Reputation points
    2021-04-09T13:51:31.76+00:00

    Hi @Bakar, Cem ,

    If you add single quote in the existing query, it should work e.g.,

    SELECT Id, ... FROM Task WHERE LastModifiedDate > '@{activity('Lookup1').output.firstRow.LastExtractRecordDate}'   
    

    You can also do datetime formatting e.g.,

    @concat('SELECT Id, ... FROM Task WHERE LastModifiedDate >''' , formatDateTime(activity('Lookup1').output.firstRow.LastExtractRecordDate, 'yyyy-MM-dd'), ''' ')  
    

    Hope this helps! Thanks! :)

    3 people found this answer helpful.
    0 comments No comments

4 additional answers

Sort by: Most helpful
  1. MartinJaffer-MSFT 26,031 Reputation points
    2021-04-09T18:23:00.527+00:00

    @Bakar, Cem
    @Nasreen Akter 's idea was my first thought also.

    So you are saying that the inline value should be datetime rather than a string representing a datetime?
    In that case remove the {curly braces}. The {curly braces} after @, mean "Turn the result of the expression into a string".
    Another possibility is re-adding the zone.

    In any case, we should all take a look at this example.

    When you specify the SOQL or SQL query, pay attention to the DateTime format difference. For example:

    SOQL sample: SELECT Id, Name, BillingCity FROM Account WHERE LastModifiedDate >= @{formatDateTime(pipeline().parameters.StartTime,'yyyy-MM-ddTHH:mm:ssZ')} AND LastModifiedDate < @{formatDateTime(pipeline().parameters.EndTime,'yyyy-MM-ddTHH:mm:ssZ')}
    SQL sample: SELECT * FROM Account WHERE LastModifiedDate >= {ts'@{formatDateTime(pipeline().parameters.StartTime,'yyyy-MM-dd HH:mm:ss')}'} AND LastModifiedDate < {ts'@{formatDateTime(pipeline().parameters.EndTime,'yyyy-MM-dd HH:mm:ss')}'}

    1 person found this answer helpful.

  2. Bakar, Cem 281 Reputation points
    2021-04-10T01:04:44.04+00:00

    It is always the last spot you look. Salesforce requires the date formatted in specific format. Including the zone.
    Without curly braces and adding time zone did the trick.

    Thank you all for your timely help!

    1 person found this answer helpful.
    0 comments No comments

  3. Viorel 112.5K Reputation points
    2021-04-09T13:42:12.423+00:00

    How did you define this query? If you see a “Manage Parameters” window — https://learn.microsoft.com/en-us/power-query/power-query-query-parameters — then try changing the type of parameter to “Date/Time”.

    0 comments No comments

  4. Bakar, Cem 281 Reputation points
    2021-04-09T15:17:34.183+00:00

    Thank you for both answering so quickly.
    @Viorel - The field type is defined as datetime2(0) - without any filter it comes back from AzureSQL like this "LastExtractRecordDate": "2021-04-08T23:59:14Z"
    However, at the sql table you do not see the zone details so it looks like this - 2021-04-09 02:05:09

    @Nasreen Akter ,
    I have tried both but regardless of how the date is presented I get the following error.86371-screen-shot-2021-04-09-at-100715-am.png