Solved

Syntax for Insert Into  using Open Query

Posted on 2011-09-08
3
302 Views
Last Modified: 2012-05-12
Hi,
i have a table called OldTable in my SqL Server, but i would like to append a new data that is sitting in another server into the OldTable.  How would i do that using open query method? Here is my situation:

OldTable:- this is the table that i would like to add some more or new data and it is my current server

NewTable:- this is a linked server and i want to bring the data in this table into the OldTable
thanks
0
Comment
Question by:karinos57
[X]
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
3 Comments
 
LVL 21

Accepted Solution

by:
JestersGrind earned 500 total points
ID: 36506065
You have to create a linked server in your SQL Server that points to the other SQL Server.  Then you would run this.

INSERT INTO OldTable (col1, col2, etc...)
SELECT *
FROM OPENQUERY(YourLinkedServerName, 'SELECT Col1, Col2, etc... FROM RemoteTableName')

Greg

0
 

Author Closing Comment

by:karinos57
ID: 36506175
thnx
0
 
LVL 40

Expert Comment

by:lcohan
ID: 36506182
if the two servers are both SQL you don't necessarily need the OPENQUERY - you need that only if you define a linked server based on a ODBC which would be a waste if bothe are SQL.
Assuming you create a linked server using "Microsoft OLEDB provider for SQL Server" just use a full name qualifier like below:

--run on the target server

insert into OldTable select * from YourLinkedServerName.YourDBname.schema_name.NewTable

this assuming they have both SAME structure - if not just provide column list for both
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

623 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