1. openrowset
condition :
sp_configure 'show advanced options', 1
reconfigure
go
sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
go
sample:
SELECT a.* FROM OPENROWSET('SQLNCLI', 'Server=someservername;Trusted_Connection=yes;',
'select @@servername') AS a;
2. openquery
condition :
create a linkedserver
IF EXISTS (SELECT * FROM master.dbo.sysservers WHERE srvname='testLinkServer')
BEGIN
EXEC sp_droplinkedsrvlogin testLinkServer,NULL
EXEC sp_dropserver testLinkServer
PRINT 'SP_DROPSERVER'
END
EXEC sp_addlinkedserver
@server='testLinkServer'--link server alias
,@srvproduct=''
,@provider='SQLOLEDB'
,@datasrc= 'someservername'
sample:
select * from openquery (testLinkServer,'select @@servername')
3. EXEC AT
CONDITION :
1).create a linkedserver
2)
exec sp_serveroption @server='testLinkServer', @optname='rpc', @optvalue='true'
exec sp_serveroption @server='testLinkServer', @optname='rpc out', @optvalue='true'
sample:
exec ('select @@servername') at testLinkServer