Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select accross servers 1

Status
Not open for further replies.

MKVAB

Programmer
Dec 2, 2003
86
0
0
US
Can somebody give me the basic syntax to perform SELECT/UPDATE statements across servers???

Verbiage:
The ultimate purpose is to update a remote DB with all information that is later than what is currently there. I want to:
1. SELECT the MAX value from the remote DB
2. Perform an INSERT with data from the local DB into the remote DB using that MAX value in the WHERE clause


Code:
Code:
DECLARE @MaxValue int
/***********************************************
** Grab value from remote server
***********************************************/
SELECT  @MaxValue = ( 
SELECT MAX(RemoteServer.Table1.FieldName)
FROM   RemoteServer.Table1

/***********************************************
** Use value to perform a select from local table 
** and insert into remote table
***********************************************/
INSERT INTO RemoteServer.Table1
SELECT *
FROM   Table1
WHERE  Table1.FieldName > @MaxValue



Ideas or suggestions greatly appreciated!
 
It's server.database.user.table

SELECT column FROM server.database..table

usually works.

Servers must be linked either all the time or by using sp_linkedserver before executing the SELECT or UPDATE. User must have rights to SELECT or UPDATE.

Sometimes the grass is greener on the other side because there is more manure there - original.
 
Thanks for the response! Sorry for the delay! My problem did originate from not having the remote server set up in linked servers. Works wonderfully now.

Thanks again.
-MK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top