Sunday 21 October 2018

Do we use parameter placeholder? In the TABLE or FROM clause in execute sql task in SSIS

I had a requirement to load the data in the staging table and before the loading the data we need to truncate the table.
We have some flat files and these files have a proper naming convention. First 5 character indicates the Staging table name. Based on the file name we need to truncate and load that data in the corresponding table.
My package design as below.
 
   
In the execute SQL task I write the parameterized SQL statement as below
     
   
Here I am mapping the parameter value
      
     
While I am ruining my package getting below error
     
   
[Execute SQL Task] Error: Executing the query "  Truncate table ?" failed with the following error: "Incorrect syntax near '@P1'.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
We cannot use the parameter placeholder? In the TABLE or FROM clause.
Instead, build our SQL statement in a variable.
Variable Sql statement
EvaluateAsExpression: True
Expression:
"TRUNCATE TABLE” + [User::table_name]
      
     
Click ok.
Then have the Execute SQL Task use that variable.
In general table we need to select SQLSourceType is Variable and assign the Source Variable.
       
     
Now click ok.
Run the package.
Before running the package.
         

Running the package.
  
       
Task executed successfully. See the records in the database table.
     
Get the expected result.


No comments:

Post a Comment

If you have any doubt, please let me know.

Popular Posts