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 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
精彩评论