Data Factory - SQL Query to Salesforce with dynamic content

Bakar, Cem 281 Reputation points
2021-01-14T04:21:07.053+00:00

I have a pipeline on Data Factory with two modules.

  • Lookup, which gets the last inserted date from SQL database.

56462-screen-shot-2021-01-13-at-111322-pm.png

  • Copy data, using the result from the lookup to execute a select query.

56366-screen-shot-2021-01-13-at-111451-pm.png

Query:

SELECT * FROM Event WHERE LastModifiedDate IS NOT NULL AND LastModifiedDate < @activity('LastModifiedDate-Event').output.firstRow.LastModifiedDate Limit 10

No matter how I restructure the query I get variety of errors.

Failure happened on 'Source' side. ? ErrorCode=UserErrorOdbcOperationFailed,'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=ERROR [22018] [Microsoft][Support] (40550) Invalid character value for cast specification.,Source=Microsoft.DataTransfer.ClientLibrary.Odbc.OdbcConnector,''Type=System.Data.Odbc.OdbcException,Message=ERROR [22018] [Microsoft][Support] (40550) Invalid character value for cast specification.,Source=Microsoft Salesforce ODBC Driver,'

SELECT TOP 1000 * FROM Event WHERE LastModifiedDate IS NOT NULL AND LastModifiedDate < @activity("LastModified-Event").output.firstRow.LastModifiedDate ORDER BY LastModifiedDate DESC
Failure happened on 'Source' side. ErrorCode=UserErrorOdbcOperationFailed,'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=ERROR [HY000] [Microsoft][Salesforce] (120) SOQL_FIRST mode prepare failure: SOQL error: [Microsoft][SQLEngine] (31480) syntax error near 'SELECT TOP 1000<<< ??? >>> * FROM Event WHERE LastModifiedDate IS NOT NULL AND LastModifiedDate < @activity("LastModified-Event").output.firstRow.LastModifiedDate ORDER BY LastModifiedDate DESC'. SQL error: [Microsoft][SQLEngine] (31480) syntax error near 'SELECT TOP 1000 * FROM Event WHERE LastModifiedDate IS NOT NULL<<< ??? >>> AND LastModifiedDate < @activity("LastModified-Event").output.firstRow.LastModifiedDate ORDER BY LastModifiedDate DESC'.,Source=Microsoft.DataTransfer.ClientLibrary.Odbc.OdbcConnector,''Type=System.Data.Odbc.OdbcException,Message=ERROR [HY000] [Microsoft][Salesforce] (120) SOQL_FIRST mode prepare failure: SOQL error: [Microsoft][SQLEngine] (31480) syntax error near 'SELECT TOP 1000<<< ??? >>> * FROM Event WHERE LastModifiedDate IS NOT NULL AND LastModifiedDate < @activity("LastModified-Event").output.firstRow.LastModifiedDate ORDER BY LastModifiedDate DESC'. SQL error: [Microsoft][SQLEngine] (31480) syntax error near 'SELECT TOP 1000 * FROM Event WHERE LastModifiedDate IS NOT NULL<<< ??? >>> AND LastModifiedDate < @activity("LastModified-Event").output.firstRow.LastModifiedDate ORDER BY LastModifiedDate DESC'.,Source=Microsoft Salesforce ODBC Driver,'

Sorry for the giant images. Please let me know if you see any issues with the query.

Azure SQL Database
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,624 questions
SQL Server Other
0 comments No comments
{count} vote

Accepted answer
  1. Vaibhav Chaudhari 38,916 Reputation points Volunteer Moderator
    2021-01-14T13:24:32.56+00:00

    Could you try below like syntax -

    select * from data_source_table where LastModifytime > '@{activity('LookupOldWaterMarkActivity').output.firstRow.WatermarkValue}'


    Please don't forget to Accept Answer and Up-vote if the response helped -- Vaibhav

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Viorel 122.5K Reputation points
    2021-01-14T09:18:19.703+00:00

    One of the errors is shown for TOP. Try adding parentheses: ‘SELECT TOP(1000)…’.

    Another error is about “IS NOT NULL”. Maybe this “” denotes a special space. Try removing and retyping this fragment.

    Also make sure that the compared values represent valid date. Maybe even try some investigations with literal dates, such as “SELECT … AND LastModifiedDate < ’2020-12-17 09:31:26’”. Or start with the simplest query that works (SELECT * FROM Event), then add other parts gradually.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.