?
Solved

SQL - remote query

Posted on 2012-08-10
2
Medium Priority
?
495 Views
Last Modified: 2012-08-11
I would like to remote query a database with a SQL statement.  I would like to insert result from the query to my local SQL server.
My task.
1. connect to remote SQL server
2. perform a remote query
3. insert result  insert into a table of a local database.

How do I do that
0
Comment
Question by:tommym121
2 Comments
 
LVL 26

Accepted Solution

by:
tigin44 earned 2000 total points
ID: 38283229
you can reference a remote server via linked servers..

first of all you should define a linked server to the remote server. you should find detatiled information in here
    http://msdn.microsoft.com/en-us/library/ms188279.aspx 
or at books online.

once you define linked server you should reference a database on that remote server by using four part name convention i.ei,
   [linkedServerName].[remoteDatabaseName].[schemaName].[databaseObjectName]


lets asume our linked server name is LS_SOME_SERVER... so aquery like this will do what you want

INSERT INTO dbo.localTableName (col1, col2, ...., coln)
SELECT col1, col2, ...., coln
FROM [LS_SOME_SERVER].[remoteDatabaseName].[dbo].[remoteTableName]
0
 

Author Closing Comment

by:tommym121
ID: 38283721
Thanks.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
Integration Management Part 2
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

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