Inserting Data into SQL Server from variables via SSIS

可紊 提交于 2019-11-29 18:02:54

I suggest you build this SQL statement in another variable, as explained here:

http://consultingblogs.emc.com/jamiethomson/archive/2005/12/09/2480.aspx

Then use that variable in your execute SQL statement

Normally you would try and parameterise the query but in this case (as in many others) it won't work.

Here are some more detailed instructions:

A. Generate the dynamic SQL

  1. Create a new SSIS variable of type string
  2. In properties, set it's 'Evaluate as Expression' to TRUE
  3. In properties, click on 'Expression' and build an expression as follows:

    "INSERT INTO Data_Result(Result) VALUES ('"+@[USER::my_data]+"')"

  4. Press Evaluate and verify that the output is valid SQL (you may even wish to paste it into SSMS and test)

B. Get an Execute SQL task to run your SQL:

  1. Drop a execute SQL task on your page. Set it's connection
  2. With the execute SQL task highlighted, go to properties and click expressions
  3. Pick the property 'SQLStatementSource'. In the expression pick your variable that you built in step A and press evaluate.
  4. Press OK on everything

Now whatever change occurs in my_data will automatically be applied to your execute SQL task

Try that for starters and get back to me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!