sql-serverazureazure-sql-databasegoogle-cloud-dataflowazure-synapse-analytics

Azure Synapse Dataflow - Unable to use a parameter in Pre SQL scripts


In my Sink I'm running a Pre SQL Script to delete data after a certain date but I'm having trouble using parameters in the script.

enter image description here

Here is my date parameter variable inside dataflow and below is my pipeline parameter and SQL script

enter image description here

DELETE FROM dbo.DAP_WD_Timecard_Analysis_Test WHERE Reported_Date > '{$date}'

This is the error I'm receiving below. I've tried using a Date type instead of String with the same result. This works when I hard code the date.

enter image description here


Solution

  • enter image description here

    To resolve the above error, you can use the below expression in the pre-copy scripts. Your parameter data type should be string.

    concat('delete from dbo.table1 where mydate >','\'',$date_param,'\'')
    

    Open the expression builder and give the above expression.

    enter image description here

    This is my input data before dataflow execution:

    enter image description here

    You can see after the dataflow execution the mentioned rows were deleted. Here, I have used the same table as source and sink in dataflow so there will be duplicates in my case which you can ignore.

    enter image description here