Inserting Data into SQL Server from variables via SSIS

Reshma picture Reshma · Sep 9, 2013 · Viewed 17k times · Source

I have consumed simple web service for addition of two numbers and I am getting the result in xml format that I have stored in variable supposed named as my_data, now I have to insert that result in my sql table named as Data_result by writing query in oledb source editor, but unable to insert data using variable.I just want to store all the result calculated by my web service in sql table.

Since I am newbie to SSIS, any help is greatly appreciated

When I am trying to insert the data by the following query command:

"INSERT INTO Data_Result(Result) SELECT '"+@USER::my_data+"'"

It's giving error:

Error at Data Flow Task [OLE DB Source [55]]: No Column Transformation was return by SQL Command

--------Updated explanation of errors based on the solution given

Error for executing query If I place the expression without the "" quotes then I get following error enter image description here

If I place the query in double quotes then following error is shown enter image description here

And if I remove User from User::Data Variable and place the query in double quotes then I get following screen enter image description here although the expression evaluates but after proceeding further on this evaluated expression when I am trying to search for the variable in expression column of Execute sql Task, then I am unable to locate the newly created variable, as shown below enter image description here

------------Updated question according to other query----------

Here is the picture of my whole work flow

enter image description here

This is what I have did inside the for each loop container under collection tab

enter image description here

And this below setting I have done between Variable mapping tab,

enter image description here

And in below screen shot, I am using Execute SQL Task to enter my data obtained from web service task into database using an insert query, but unable to fire proper insert query,

enter image description here

And below is my XML file,

<?xml version="1.0" encoding="utf-16"?>

Reshma

1988-09-23T00:00:00 ,

This name and birthdate I received from web service I want to insert that into database table

--------------Updated question for foreach loop container--------

Below is the foreach loop container I am using,

enter image description here

But still I am not getting node value into variable and also I am suppose to make use of object type variable or it can work with string type of variable.

Answer

Nick.McDermaid picture Nick.McDermaid · Sep 9, 2013

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.