Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 query from another server

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2009-05-31 : 02:12:05
Is there a way I can query another server (in a stored procedure)
Like i'm on server yyyy and I want to query server xxxx.dbo.mydb.users

is this possible? I assume I would have to pass the user credentials somewhere in the query but where?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-31 : 02:13:32
check out linked server


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

a.rameshk
Starting Member

19 Posts

Posted - 2009-05-31 : 03:44:45
As we want to access the data from other server.First we need to create Linked server using sp_addlinkedserver syntax.
After successfully creating the linked server we can write a query like this and get the data.
For Eg: SELECT *FROM LinkedServer.DatabaseName.dbo.TableName.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-31 : 06:25:28
if its for an adhoc access you can use OPENDATASOURCE which does not require setting up a linked server connection.
Go to Top of Page
   

- Advertisement -