I want to truncate tables where the value of my column isTrun in the config table is True.
The scripts need to run in the Sink pre-copy script of the copy activity.
The dataflow is the following:
The look-up activity looks up the config table. Then enters the for each loop and copy’s the tables that are looked up. before the copy, there needs to be a truncate for the tables that have in the config table the value True in the isTrun column.
The problem that I am facing is that all my tries have invalid syntax.
I already tried the followings scripts:
if(@item().isTrun = 1, TRUNCATE TABLE [@{item().targetSchema}].[@{item().targetTable}], '1=1')
and this script:
TRUNCATE TABLE @{if(equals(item().isTrun, 'True'),'[@{item().targetSchema.item()}].[@{targetTable}]',' ')}
Thanks in advance!
2
Answers
pre-copy script
that you can use to achieve the requirement.isTrun
value is True, then if condition checks and executes the truncate statement and ignores if the isTrun value is false. The following is table t2 (1 row in source and sink) after the above execution (isTrun is false).Use this expression for the pre-copy script:
It checks if isTrun equals 1 for this loop, if so it concatenate the truncate command with the table name. If not, the pre-script will be an empty string that does nothing.