user278618
user278618

Reputation: 20242

Join two tables at the same server

I have two databases at the same server 192.168.1.100 DB1 and DB2

When I'm trying to execute :

select h.code,eh.Defaultname From hotels h JOIN [192.168.1.100].[dbo].[DB2].Hotels eh ON h.code = eh.code

I get

Could not find server '192.168.1.100' in sysservers. Execute sp_addlinkedserver to add the server to sysservers.

I don't understand :/

I'm using ms sql server 2005 and this query is fired when I'm at DB1.

What's the reason of this , and how to fix it ? :/

Upvotes: 1

Views: 463

Answers (2)

Damir Sudarevic
Damir Sudarevic

Reputation: 22187

JOIN [DB2].[dbo].[Hotels] AS eh

Upvotes: 1

Blorgbeard
Blorgbeard

Reputation: 103447

Since the databases are on the same SQL Server instance, you don't need to use a linked server, so don't specify the IP, just the other database's name.

select h.code,eh.Defaultname 
From hotels h 
JOIN [DB2].dbo.Hotels eh ON h.code = eh.code

Upvotes: 3

Related Questions