Connecting to a SQL Server through another Sever connection that's not linked -


so tasked creating query uses data 2 separate databases on 2 separate servers. i've been told linking servers not option there sql command can used address server want connect to. can clue me in on command might be?

ex:

server 01 database_01 table01

server 02 database_02 table02

if had linked server this.

select s2.*, s1.somefield [server 02].[database_02].[table02] s2 join  [server 01].[database_01].[table01] s1 on s2.id = s1.id 

since don't have option, need find way reference server 02 if connected server 01.

you'd need either openrowset or opendatasource

found examples here:

openrowset:

select * openrowset('sqlncli',    'driver={sql server};server=myserver;uid=myuserid;pwd=mycleverpassword',    'select @@servername')  

opendatasource:

select *  opendatasource ('sqlncli', -- or sqlncli    'data source=otherserver\instancename;catalog=remotedb;user id=sqllogin;password=secret;').remotedb.dbo.sometable 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -