开发者

Join two tables at the same server

开发者 https://www.devze.com 2023-01-19 05:35 出处:网络
I have two databases at the same server 192.168.1.100 DB1 and DB2 When I\'m trying to exe开发者_JS百科cute :

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

When I'm trying to exe开发者_JS百科cute :

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 ? :/


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号