Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

SSIS update a table based on another table

Posted on 2014-10-17
17
581 Views
Last Modified: 2016-02-11
Hi,

I have the below scenario

SqlServer1
Table1
Columns: Name(Varchar), Active(bit)

SqlServer2
Table2
Columns: Name2(Varchar), Active(bit)

I want SSIS to update the 'Active' column in table two depending on the value in 'Active' in table one. How can I do this in SSIS. I currently have two OLE DB Sources that then get sorted seperately, now im a little stuck on where / to join the two then put an update command in there for table2 based on table1?

Thanks,
Dean
0
Comment
Question by:deanlee17
  • 8
  • 6
  • 3
17 Comments
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40386588
You can set up a connection, then use an "Execute SQL" task.
0
 
LVL 17

Expert Comment

by:OriNetworks
ID: 40386600
In the execute sql task a simple Update with a join should take care of it
  update tblTest  SET tblTest.Active=t2.Active
  from tblTest t1 inner join tblTest2 t2 on t1.Name=t2.Name2

Open in new window

0
 

Author Comment

by:deanlee17
ID: 40386602
Ok, where do I go to setup an execute SQL task. This is my first day using SSIS so sorry for silly questions
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

Author Comment

by:deanlee17
ID: 40386607
Ah, in the control flow! I was just working in the data flow tab
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40386610
SSIS Toolbox.

If you haven't used SSIS before, you really need a book on it. I can suggest the Microsoft 70-463 official exam book.
0
 
LVL 17

Expert Comment

by:OriNetworks
ID: 40386616
Execute SQL is available from the toolbox. If you don't see toolbox in the designer you can use the View menu to select Toolbox. If this is your first SSIS package you may want to get familiar with it by following a tutorial first. Here is some information about the Execute SQL task:
http://msdn.microsoft.com/en-us/library/ms141003.aspx
0
 

Author Comment

by:deanlee17
ID: 40386628
Thanks for the advice and links, I will be purchasing a book shortly, but need this done asap.

So for my example I dont need the data flow task that I was working on and it can all be done in one single "Execute SQL", which is confusing at it only takes one connection and obviously I need two.
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40386635
You only need one connection, because presumably both tables are in the same database - that's the connection.
0
 
LVL 17

Expert Comment

by:OriNetworks
ID: 40386641
You can register a linked server in SQL Server from SSMS under Server Objects -> Linked Servers. The query could then be written by specify the server name and running the new query from server1

update Table1  SET Table1.Active=t2.Active
  from  Table1t1 inner join Server2.DB2.Table2 t2 on t1.Name=t2.Name2
0
 

Author Comment

by:deanlee17
ID: 40386647
Thanks guys,

Phil, they are different databases.

OriNetworks, Enquired about this approach and manager doesnt want to link servers.
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40386657
Then you need to the Data Flow, have two sources, and use a Lookup.
0
 

Author Comment

by:deanlee17
ID: 40386676
Which lookup tool? Image attached of project so far.

situation.png
The merge join contains two columns from each side
0
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 500 total points
ID: 40386682
I can't see the picture. However, you can use the Lookup tool in the Data Flow instead of the merge join.

Have a look at this video: http://www.youtube.com/watch?v=WMfuXYsWZqM
0
 

Author Comment

by:deanlee17
ID: 40386813
Ok, useful link....

So I used OLE DB Source to get the base data (Syspro), then added a lookup to bring in the destination file (Ascent) and link on 'Name'. So now I went into control flow and added 'Execute SQL task' to use the SQL code:

UPDATE       AscentCheck
SET                AscentActive = dbo.SysproBase.SysproActive
FROM            AscentCheck INNER JOIN
                         SysproBase ON AscentCheck.AscentName = dbo.SysproBase.SysproName

It can find the destination database / tables (Ascent),  but it cannot find the original data source (Syspro)

Thanks,
Dean
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40386843
If you have two sources, and you do the lookup, the next thing you need is a destination (within the data flow) to save the data. You shouldn't need the Execute SQL task at all.
0
 

Author Comment

by:deanlee17
ID: 40386899
Two sources, both sorted, filtering into a merge join. Trying to add OLE DB Destination and it wont let me do an Update Query, am I doing it in the right place?
0
 

Author Comment

by:deanlee17
ID: 40391458
Anybody?
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question