Re: Variable server names
- From: Erland Sommarskog <esquel@xxxxxxxxxxxxx>
- Date: Thu, 02 Jul 2009 14:38:40 -0700
Rick (rick0726@xxxxxxxxxxx) writes:
Thanks for this. We already have (permanent) linked server
relationships between the current server and all the the remote
servers I could possibly be passing in as a variable. So I'm assuming
I don't need to execute the SP_ADDLINKEDSERVER and SP_DROPSERVER that
you indicate below.
As I said, I did not see your original post, so I may be missing some
context, but I understood it as management wanted to connect to a server
that was determined at run-time.
My idea was then you have have a fixed server name that you would
use in your code, but that yould define the definition to point at
the current linked server.
I have a table on the local server into which I need to insert data
from both (1) a table on the local server AND (2) a table on the
remote server. My initial thought was to first populate the local
table with the local data, then execute the remote proc -- its named
passed in as a parm -- as you do here to insert the remote data into
the local. The problem is that the table is declared as a table
variable, and when I do--
INSERT INTO @mytable
EXEC @Server_and_DB_and_ProcName
I'm warned that:
EXECUTE cannot be used as a source when inserting into a table
variable.
So my backup plan was to do this all in a single proc. I was hoping
to avoid dynamic SQL since mixing dynamic SQL and a table variable
doesn't make me very happy. Any thoughts?
The restriction on INSERT-EXEC and table variables has been lifted in
SQL 2005, but any reason you cannot use a temp table instead?
If all you need to do on the linked server is to run procedures,
building a string with the procedurename like above, is definitely the
best way to go.
--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx
Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
.
- Follow-Ups:
- Re: Variable server names
- From: Rick
- Re: Variable server names
- References:
- Variable server names
- From: Rick
- Re: Variable server names
- From: Eric Isaacs
- Re: Variable server names
- From: Rick
- Re: Variable server names
- From: Erland Sommarskog
- Re: Variable server names
- From: Rick
- Variable server names
- Prev by Date: Update only what passed
- Next by Date: Re: Indexed views question
- Previous by thread: Re: Variable server names
- Next by thread: Re: Variable server names
- Index(es):
Relevant Pages
|