Wednesday, February 22, 2012

SQL-Server Query from your SQL-Server

Note :
To execute other SQL-Server SQL Query from your SQL-Server

To Enable This Option Follow Step 1 and 2

#####Step 1

sp_configure 'show advanced options', 1;
RECONFIGURE;

#####Step 2


sp_configure 'Ad Hoc Distributed Queries', 1;
RECONFIGURE;


#####Step 3 - Execute Your Query
SELECT top 10 *
FROM OPENROWSET('SQLNCLI','Server=DbServerName;Uid=username;Pwd=password;Database=databasename;',
'SELECT * FROM tabelname') AS FS




sp_configure 'show advanced options', 1;
RECONFIGURE;
sp_configure 'Ad Hoc Distributed Queries', 1;
RECONFIGURE;