Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

SSIS insert / update question from one server table to a table on another server

Posted on 2014-08-21
3
Medium Priority
?
573 Views
Last Modified: 2016-02-11
I want to select some fields from a table on one server and automatically create them in another table on another server

so SSIS package needs to do following

select field1, field2 from server1.table1

delete from server2.table2

insert into server2.table2
values field1, field2
from server1.table1

what's the code / steps for doing this? I'm a bit lost! was thinking of a package in SSIS but is this more a stored procedure?
0
Comment
Question by:Chris Michalczuk
3 Comments
 
LVL 23

Expert Comment

by:rhandels
ID: 40276108
You can use a package for this. Making an SQL statement for the select of the old database is no problem. First create a OLDEDB Source and type in the correct statement you need to use.
After that, create an OLEDB destination, select the database you need to copy the information in. Either select an allready created database (if you have one) or ask it to create a new table for you.

Problem with this setup is that if you run the SSIS package it will add the information from your source to your destination and will add all records (not delete the old ones).

What i do now is just delete the information from the database. To do this you add an SQL execute statement task and type in delete from <destination_database>, then go to the data transormation task in which you tell it to copy info from source to destionation.
0
 
LVL 53

Expert Comment

by:Vitor Montalvão
ID: 40276334
You want to do it only once or in a regular way?

For a regular way and with schedules, then using SSIS will be a solution.

For one shoot only you can use Database Import/Export Wizard or T-SQL as:
INSERT INTO server2.table2
SELECT field1, field2 FROM
OPENROWSET('SQLNCLI',
           'Server='server1';Trusted_Connection=yes;
           'SELECT field1, field2 FROM databasename1.table1 )

Open in new window

0
 
LVL 15

Accepted Solution

by:
Vikas Garg earned 2000 total points
ID: 40280421
Hi,

In SSIS you can have package having Data flow task and Execute sql task.

First DFT - Data flow task will load data from Server1.table1 to Server2.table2 and then execute sql task to delete rows from server1.table1
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses

578 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