Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

SSIS Update table based on the resultset of a SQL Statement Expand / Collapse
Author
Message
Posted Monday, February 24, 2014 1:39 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, March 6, 2014 10:11 AM
Points: 12, 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
Post #1544701
Posted Monday, February 24, 2014 5:15 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, May 5, 2014 6:31 AM
Points: 288, Visits: 519
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
Post #1544743
Posted Tuesday, February 25, 2014 8:10 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, March 6, 2014 10:11 AM
Points: 12, 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
Post #1544954
Posted Tuesday, February 25, 2014 8:22 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, May 5, 2014 6:31 AM
Points: 288, Visits: 519
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.
Post #1544967
Posted Tuesday, February 25, 2014 8:43 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, March 6, 2014 10:11 AM
Points: 12, 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.
Post #1544977
Posted Tuesday, February 25, 2014 8:51 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, May 5, 2014 6:31 AM
Points: 288, Visits: 519
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.
Post #1544982
Posted Tuesday, February 25, 2014 8:58 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, March 6, 2014 10:11 AM
Points: 12, 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?
Post #1544986
Posted Tuesday, February 25, 2014 9:04 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, May 5, 2014 6:31 AM
Points: 288, Visits: 519
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.



Post #1544988
Posted Tuesday, February 25, 2014 10:41 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, March 6, 2014 10:11 AM
Points: 12, 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?
Post #1545058
Posted Tuesday, February 25, 2014 11:07 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, May 5, 2014 6:31 AM
Points: 288, Visits: 519
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.
Post #1545072
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse