SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SSIS Update table based on the resultset of a SQL Statement


SSIS Update table based on the resultset of a SQL Statement

Author
Message
WheelsGuy
WheelsGuy
SSC-Enthusiastic
SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)

Group: General Forum Members
Points: 190 Visits: 24
Good afternoon.

I have two different databases (on two different servers) and I would like to use SSIS to update a table on server 2 / database 2 with the resultset from a SQL statement from server 1 / database 1. The result set from the query will be used in the IN clause of a WHERE statement.

I have a OLE DB Source to a Lookup to a Conditional Split to a OLE DB Command (upddate), but I am having trouble getting it to work. Could someone tell me what components I should be using, and in what order? I read online to use a For Each to create a string variable of the resultset.

Thank you, WHEELS
EricEyster
EricEyster
Right there with Babe
Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)

Group: General Forum Members
Points: 746 Visits: 520
I don't have a set of screen shots handy, but these are my normal steps:

1) create a SSIS variable
2) use a SQL task to query they first database
3) use the results tab of the SQL task to put the output into the variable
4) create the second task (sql command, flow etc) with a ? as the marker for the variable
5) use the parameter tab to bind in the variable
WheelsGuy
WheelsGuy
SSC-Enthusiastic
SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)

Group: General Forum Members
Points: 190 Visits: 24
EricEyster (2/24/2014)
I don't have a set of screen shots handy, but these are my normal steps:

1) create a SSIS variable
2) use a SQL task to query they first database
3) use the results tab of the SQL task to put the output into the variable
4) create the second task (sql command, flow etc) with a ? as the marker for the variable
5) use the parameter tab to bind in the variable


Thnak you Eric. After my online research I did something similar to what you had suggested, but I failed. I am fairly new to SSIS (and even newer to variables). Let me elaborate on what I believe your steps are outlining:

1) Go to Variables, click Add Variable, giveit a name, Scope is Package, and Data Type is String.
2) In the Control Flow (tab) add a Execute SQL task. In the SQLStatement (General section), put the SQL that queries from the table on database 1 (server1), and add the Connection.
3) In the Parameter Mapping Add the Variable Name (User::VarName), Direction set to Output, and DataType set to NVARCHAR. The Add button is disabled under Result Set.
4) I have a Data Flow Task and the (Green) output of the Execute SQL task is going into the Data Flow Task. On the Data Flow tab, I have a OLE DB Source with the SQL that queries from the table on database 1 (server1), going into a Lookup, going into a Conditional Split, and ending up going to a OLE DB Command (table update on database 2 (server2)).
5) Not sure how or where to bind the variable (parameter tab?).

WHEELS
EricEyster
EricEyster
Right there with Babe
Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)

Group: General Forum Members
Points: 746 Visits: 520
WHEELS,
I hve BIDS open to refresh my memory on this. On task 1, the select from the source, look for ResultSet and select "single row". This will enable the Result Set section. Parameter mapping = output would only be used if you have a stored procedure with and output parameter, which is not the case here.
WheelsGuy
WheelsGuy
SSC-Enthusiastic
SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)

Group: General Forum Members
Points: 190 Visits: 24
Getting closer. I set ResultSet to Single row, and I was able to add the variable in the Result Set section. In the Data Flow (OLE DB SOurce) I put SQL command from variable in the Data access mode, and selected the variable in the Variable name drop-down. When I click Preview or OK, I get Error at Data Flow Task: Command text was not set for the command object.
EricEyster
EricEyster
Right there with Babe
Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)

Group: General Forum Members
Points: 746 Visits: 520
close.
the statement from variable would be used if you have a script task that assembles the full query text. That is not the case here. Use "Direct Input" and paste the select into the SQLStatement block. It should look like

select *
from test
where c1 = ?

next, go to parameter mappings and add a new param, pick you variable and data type.
WheelsGuy
WheelsGuy
SSC-Enthusiastic
SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)

Group: General Forum Members
Points: 190 Visits: 24
EricEyster (2/25/2014)
close.
the statement from variable would be used if you have a script task that assembles the full query text. That is not the case here. Use "Direct Input" and paste the select into the SQLStatement block. It should look like

select *
from test
where c1 = ?

next, go to parameter mappings and add a new param, pick you variable and data type.


I'm a bit confused (too much multitasking). In the Execute SQL task, I have Direct input, and the SQLStatement I need to grab the variable data. Would the example SQL you listed be in the OLE DB Source of the Data Flow or somewhere else?
EricEyster
EricEyster
Right there with Babe
Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)

Group: General Forum Members
Points: 746 Visits: 520
WheelsGuy (2/25/2014)
EricEyster (2/25/2014)
close.
the statement from variable would be used if you have a script task that assembles the full query text. That is not the case here. Use "Direct Input" and paste the select into the SQLStatement block. It should look like

select *
from test
where c1 = ?

next, go to parameter mappings and add a new param, pick you variable and data type.


I'm a bit confused (too much multitasking). In the Execute SQL task, I have Direct input, and the SQLStatement I need to grab the variable data. Would the example SQL you listed be in the OLE DB Source of the Data Flow or somewhere else?



Sorry, multitasking myself.
Your second step: is it an update statement or a data flow? If you are updating or inserting a record on the second system, you can use a ExecuteSQL task. Data flow would be for pulling many records to the second system.
WheelsGuy
WheelsGuy
SSC-Enthusiastic
SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)SSC-Enthusiastic (190 reputation)

Group: General Forum Members
Points: 190 Visits: 24
EricEyster (2/25/2014)
WheelsGuy (2/25/2014)
EricEyster (2/25/2014)
close.
the statement from variable would be used if you have a script task that assembles the full query text. That is not the case here. Use "Direct Input" and paste the select into the SQLStatement block. It should look like

select *
from test
where c1 = ?

next, go to parameter mappings and add a new param, pick you variable and data type.


I'm a bit confused (too much multitasking). In the Execute SQL task, I have Direct input, and the SQLStatement I need to grab the variable data. Would the example SQL you listed be in the OLE DB Source of the Data Flow or somewhere else?



Sorry, multitasking myself.
Your second step: is it an update statement or a data flow? If you are updating or inserting a record on the second system, you can use a ExecuteSQL task. Data flow would be for pulling many records to the second system.





My second step is a Data Flow Task on the Control Flow tab. Then on the Data Flow tab it is a OLE DB Source. Just looking to do an update. Are you stating that I can simply use two Execute SQL tasks on the Control Flow tab?
EricEyster
EricEyster
Right there with Babe
Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)

Group: General Forum Members
Points: 746 Visits: 520
Yes, SSIS does not have any requirements as far as what tasks you use. We have a few packages that do nothing but call stored procedures and run VB script tasks. It was just easier to wrap them in a package than compiling an executable.

If you are going to run an update on the second DB, write a simple stored procedure with a parmater. It will be easier to maintain down the road and not require any changes to the package.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search