Sample Header Ad - 728x90

How can I execute Openrowset in the named instance I am currently in?

1 vote
1 answer
163 views
I am running this openrowset query about jobs on my current server and I see that the result set is not correct. I was expecting a bunch of jobs but I only get one. when I run the following piece of code I can see why:
select [my current server] = @@servername

select *
from openrowset('SQLNCLI','Server=(local);Trusted_Connection=yes;',
'select [my current server] = @@servername') AS a
that gives me the following result: enter image description here 'MATHURA` is my server name (machine name) 'MATHURA\SQL2016` is the server name\instance name where I am executing this query obviously when I pass Server=(local); to the openrowset it takes it to be my server name, but I am running on the mathura\sql2016 instance. the question is: how can I pass the currently named instance to the openrowset ?
Asked by Marcello Miorelli (17274 rep)
Jun 29, 2025, 04:29 PM
Last activity: Jun 30, 2025, 01:06 AM