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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Output from one server as input to another

Status
Not open for further replies.

RenaG

Programmer
May 3, 2011
132
0
0
US
I need to write a query against one server and use the results as input to a query written against another server. This is a one-time request so it isn't something I need to set up to run automatically or anything. I could even export the results to an Excel spreadsheet and use that as input if this is possible. I am using SQLServer 2012 and SQL Server Management Studio as my SQL tool.

TIA,
~RLG
 
Have you considered linked servers? Another option, write the query results to a temporary table. Copy or export that table to the other server to use as input.

==================================
The trouble with doing something right the first time is that nobody appreciates how difficult it was - Steven Wright


 
Hi John,

I had considered the temp table option but I don't know how to copy or export the table to the other server. I also don't know how to link the servers. Is that done inside the query? Can you give me some code examples for both of these options? Thanks!

~RLG
 
you ncan link servers in SQL Server Management Studio or from command line, but to do so you need administrators rights on server. But if it is not set and it is only one time deal you can just run export/ import wizard in SQL Server Management Studio
 
According to the OP: "This is a one-time request so it isn't something I need to set up to run automatically or anything. "

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
One final thought, for someone who maybe doesn't have sa rights. Write the data to a table on server 1. Create an identical table on server 2. Use bcp or SSIS to export the data to a delimited file on server 1. sftp the file from server 1 to server 2. Use bcp or SSIS to import the data into the table on server 2. Run your query on server 2.

==================================
The trouble with doing something right the first time is that nobody appreciates how difficult it was - Steven Wright


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top