Showing posts with label folks. Show all posts
Showing posts with label folks. Show all posts

Wednesday, March 21, 2012

Remote Stored Procedure exec from variable

Hello Folks,

I have a server that is linked to several other servers. I have been able to successfully execute a procedure manually to each from the common server by executing this:

exec server1.dbname.owner.procedure
go
exec server2.dbname.owner.procedure
go
exec server3.dbname.owner.procedure
go

While this is ok, I'd like to wrap this in a loop to execute the procedure but switch out the server name in each iteration (something like this):

while @.variable is not null
begin
select @.server = 'change name in loop'
select @.str = @.server+'.dbname.owner.procedure'
exec @.str
end

This unfortunately does not work. The execute is acting like the server portion of the name does not exist (defaulting to local). I have attempted to use the AT SERVERNAME syntax in a similar fashion and been unsuccessful.

Is there some way I could dynamically create the four part name and execute it?

Any assistance would be greatly appreciated.

Thanks, Mark

DECLARE @.server nvarchar(128)

DECLARE @.cmd nvarchar(1000)

SET @.server = 'MyServer'

SET @.cmd = 'EXEC ' + @.server + '.MyDatabase.MySchema.MySproc'

EXEC (@.cmd)

Monday, March 12, 2012

Remote Query results

Folks,
Can anyone help me with getting results of a query that I'm trying to
execute on a linked server into a local table? I'm trying to avoid the
DTS package as I will have to create the DTS package on every single
linked server.
I have quite a few servers that I want to execute a proc on and store
the results of all of them into one central database table.
ThanksThis is a multi-part message in MIME format.
--000502000604040203080207
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
BS wrote:
> Folks,
> Can anyone help me with getting results of a query that I'm trying to
> execute on a linked server into a local table? I'm trying to avoid the
> DTS package as I will have to create the DTS package on every single
> linked server.
> I have quite a few servers that I want to execute a proc on and store
> the results of all of them into one central database table.
> Thanks
>
Hi
There are as such no difference in inserting data from a linked server
into a local table than doing it with data from the local server. You
can use INSERT INTO or SELECT INTO. Since you don't tell anything about
the stored proc you want to run, it's difficult to to know what it
returns, but you can look up the syntax for INSERT INTO and SELECT..INTO
in Books On Line.
Regards
Steen Schlüter Persson
Databaseadministrator / Systemadministrator
--000502000604040203080207
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
BS wrote:
<blockquote
cite="mid1154381185.831914.162800@.m73g2000cwd.googlegroups.com"
type="cite">
<pre wrap="">Folks,
Can anyone help me with getting results of a query that I'm trying to
execute on a linked server into a local table? I'm trying to avoid the
DTS package as I will have to create the DTS package on every single
linked server.
I have quite a few servers that I want to execute a proc on and store
the results of all of them into one central database table.
Thanks
</pre>
</blockquote>
<font size="-1"><font face="Arial">Hi<br>
<br>
There are as such no difference in inserting data from a linked server
into a local table than doing it with data from the local server. You
can use INSERT INTO or SELECT INTO. Since you don't tell anything about
the stored proc you want to run, it's difficult to to know what it
returns, but you can look up the syntax for INSERT INTO and
SELECT..INTO in Books On Line.<br>
<br>
<br>
-- <br>
Regards<br>
Steen Schlüter Persson<br>
Databaseadministrator / Systemadministrator<br>
</font></font>
</body>
</html>
--000502000604040203080207--

Remote Query results

Folks,
Can anyone help me with getting results of a query that I'm trying to
execute on a linked server into a local table? I'm trying to avoid the
DTS package as I will have to create the DTS package on every single
linked server.
I have quite a few servers that I want to execute a proc on and store
the results of all of them into one central database table.
ThanksBS wrote:
> Folks,
> Can anyone help me with getting results of a query that I'm trying to
> execute on a linked server into a local table? I'm trying to avoid the
> DTS package as I will have to create the DTS package on every single
> linked server.
> I have quite a few servers that I want to execute a proc on and store
> the results of all of them into one central database table.
> Thanks
>
Hi
There are as such no difference in inserting data from a linked server
into a local table than doing it with data from the local server. You
can use INSERT INTO or SELECT INTO. Since you don't tell anything about
the stored proc you want to run, it's difficult to to know what it
returns, but you can look up the syntax for INSERT INTO and SELECT..INTO
in Books On Line.
Regards
Steen Schlter Persson
Databaseadministrator / Systemadministrator