Query from different sql server


EXEC sp_configure 'show advanced options', 1
RECONFIGURE
GO
EXEC sp_configure 'ad hoc distributed queries', 1
RECONFIGURE
GO

SELECT  *
FROM OPENDATASOURCE('SQLNCLI',
 ' Data Source=******;User ID=******;Password=****** ')
 .[databseName].[dbo].[tableName]
GO

PS: First ‘show advanced options’ and ‘Ad Hoc Distributed Queries’ turn on and then use sql OPENDATASOURCE command first parameter provider and second parameter is connection string that you want to connect.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s