By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,363 Members | 2,417 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,363 IT Pros & Developers. It's quick & easy.

Join Query

P: 54
hi,

in sql server,
i want to join two table in different server using join query.
guide me

thanks,
murugavel
Jun 18 '08 #1
Share this Question
Share on Google+
1 Reply


deepuv04
Expert 100+
P: 227
Hi,

If you want to retrieve data from another server or remote server, you need to add it to linked servers. Then only you can retrieve the data from that server,

use the following code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. USE MASTER
  3. GO
  4. EXEC master.dbo.sp_addlinkedserver
  5.    @server = 'SERVER_NAME',  --This is an ODBC connection that is setup on the machine.
  6.    @srvproduct = '',
  7.    @provider = 'SQLNCLI',
  8.    @datasrc = 'SERVER_NAME',
  9.    @catalog = 'DATABASE_NAME'
  10. go
  11. EXEC master.dbo.sp_addlinkedsrvlogin
  12.     @rmtsrvname=N'SERVER_NAME',
  13.     @useself=N'False',
  14.     @locallogin=NULL,
  15.     @rmtuser=N'USER_NAME',
  16.     @rmtpassword='PASSWORD'
  17.  
  18. go
  19.  
  20.  
  21.     SELECT * 
  22.     FROM OpenQuery([SERVER_NAME], 'select * from Table_Name') AS T1 INNER JOIN
  23.          Table_Name AS T2 ON T1.Column_Name = T2.Column_Name 
  24.  
  25.  
Thanks
Jun 18 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.