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 ? :/
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
Related
For instance I would like to know whether the instance I'm connecting to is running on S0, S1, S2... from a TSQL query.
Please try the following query:
SELECT d.name,
slo.*
FROM sys.databases d
JOIN sys.database_service_objectives slo
ON d.database_id = slo.database_id;
I am finding it difficult to join 2 tables across 2 servers in SQL server.
I know i am able to do this through a linked server. On my server 1 it has server 2 in its linked server folder in SSMS.
Server 1 = S1
Server 2 = S2
How do i reference the tables for a linked server join. I have tried
SELECT *
FROM [S1].[db1].[dbo].[Order] T1
JOIN [S2].[db1].dbo.[Invoice] T2
ON T1.[OrderID] = T2.[InvoiceID]
All the table names and server names are correct and server 2 is in the linked server folder under 'S2' but when i run this it says S2 and its table are invalid object names.
Any help would be appreciated
You dont need to specify the local server on your query cause it's not a linked server. So change your query to:
SELECT *
FROM [db1].[dbo].[Order] T1
JOIN [S2].[db1].dbo.[Invoice] T2
ON T1.[OrderID] = T2.[InvoiceID]
I have 2 databases with the same tables and views, one in SQL Server 2008 and another in SQL Server 2000.
I wrote this query and it works in SQL Server 2008, but it didn't work in SQL Server 2000.
How can I change my code to work in SQL Server 2000 ?
SELECT
SUM(NA_DA) OVER (PARTITION BY vd.SI_VoucherH) AS a,
SUM(NA_CA) OVER (PARTITION BY vd.SI_VoucherH) AS b
FROM
acc.ACC_VOUCHERH vh
INNER JOIN
acc.Acc_VoucherD vd ON vh.SI_VoucherH = vd.SI_VoucherH
It's hard to say w/o knowing which table NA_DA & NA_CA are coming from or knowing which table has SI_VoucherH as it PK and which has it a FK.
Hopefully the following will get you close...
SELECT
vda.NA_DA,
vda.NA_CA
FROM
acc.ACC_VOUCHERH vh
JOIN (
select
vd.SI_VoucherH,
NA_DA = Sum(vd.NA_DA),
NA_CA = SUM(NA_CA)
FROM
acc.Acc_VoucherD vd
GROUP BY
vd.SI_VoucherH
) vda
on vh.SI_VoucherH=vda.SI_VoucherH;
Is there anyway that we can list out the linked servers coming to a SQL server? I am trying to catch all the connections coming to a SQL Server. Please help!!
Thanks
Execute prcoedure: sp_linkedservers
MSFT article describing this procedure
or maybe if you want more info:
SELECT *
FROM sys.Servers a
LEFT OUTER JOIN sys.linked_logins b ON b.server_id = a.server_id
LEFT OUTER JOIN sys.server_principals c ON c.principal_id = b.local_principal_id
I have 2 SQL servers. I need a SQL query that can join 2 tables that are in two different server.
Like
SELECT *
FROM Server1.Db1.dbo.table1 A
INNER JOIN Server2.Db1.dbo.table2 B ON A.Id = B.Id
and I do not have the server names, instead I am using IP address of the servers. Do I need to enable these SQL servers as linked server to allow such cross server queries?
You can proceed with Linked Servers using sp_addlinkedserver.
Once done, you can query your data as you mentioned;
SELECT *
FROM [Db1].[dbo].table1 A
INNER JOIN [Server2].[Db1].[dbo].table2 B
ON A.Id = B.Id
Yes, add as linker server is one option. You also can join the remote table by use [ip address].dbname.dbo.table name s well.