How to Pass Variable Value to Script Task to Update Table

Lilly W 130 Reputation points
2023-08-17T22:35:44.5233333+00:00

I have a dynamic variable. How do you pass it to a script task in an ADF pipeline to update a table? I tried this. The error is "Incorrect synax near 'MydB'."

update MyDB.dbo.MyTable

set column1 = @variables('MyDynamicVariable')),

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Nandan Hegde 36,716 Reputation points MVP Volunteer Moderator
    2023-08-18T03:34:03.54+00:00

    Hey,

    Can you please suggest which database are you executing the script ? (Azure SQL DB, SQL MI etc)?

    Also is that the complete logic within the script task?

    Below should be the sample aspect :
    update MyDB.dbo.MyTable

    set column1 = @{variables('MyDynamicVariable')}

    And can you provide a screenshot of the input window of script task after execution :

    User's image

    And copy the text and try executing the script as is on database via SSMS as a debugging purpose as well

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Subashri Vasudevan 11,306 Reputation points Volunteer Moderator
    2023-08-18T03:52:10.9966667+00:00

    Hi Lilly W

    You can use the below format. (with a where clause, too)

    @concat('update MyDB.dbo.MyTable set column1 =',variables('MyDynamicVariable'),
    ' where someothercolumn= ',variables('someothervariable'))
    
    
    

    As Nandan mentioned, you can use the query without concat too by mentioning variable name inside { }, like below -

    update MyDB.dbo.MyTable set column1 = @{variables('MyDynamicVariable')}

    Please try and let us know if this helps.

    0 comments No comments

Your answer

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