SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


insert data using dynamic open row set


insert data using dynamic open row set

Author
Message
syamala.popuri
syamala.popuri
SSC Rookie
SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)

Group: General Forum Members
Points: 39 Visits: 42
Hi all,
i have 20 servers in each server we have sp with name ].[SP_SQL_Server_Info_HADB_ToReport].

TO INSERT SP RESULTS INTO ONE CENTRAL SERVER table i used fallowing query.
use master
Insert Into dbo.Server_Details_Table
select A.*
FROM
OPENROWSET ('SQLNCLI10', 'server=HADB;trusted_connection=yes',
'set fmtonly off exec [MASTER].[dbo].[SP_SQL_Server_Info_HADB_ToReport]')as A

NOW my query is how tochange above query to insert sp results from all servers(i.e dynamic open row set based on servername)

with 1) window s authentication(to server)
2) SQL AUTHENTICATION (to server)

thanks in advance
Sridevi
Robert klimes
Robert klimes
Hall of Fame
Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)

Group: General Forum Members
Points: 3221 Visits: 3452
One way to accomplish this would be to create a linked server for all servers you would like this SP to run on then create a cursor that will loop through all names in sys.servers and use the name to in dynamic sql to create the insert-exec statements. By creating linked servers, you will not have to use openrowset either, just basic insert-exec

insert into spresults
exec [Linked_server].[MASTER].[dbo].[SP_SQL_Server_Info_HADB_ToReport]



If you do not want to create the linked servers then you can create a table that will have all your server names, and just have cursor loop through that, using your openrowset query.

Bob
-----------------------------------------------------------------------------
How to post to get the best help
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search