|
-
Aug 3rd, 2005, 09:50 AM
#1
Thread Starter
Fanatic Member
Joining Tables From Diff Databases
Hi there,
i have 2 databases one and MSDE and the other a SQL SERVER database.
I would like to be able to join a table in my MSDE table (Stock) to a table in the SQL Server(Products)
how is this possible, or is it?
can this be done as a stored procedure?
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
-
Aug 3rd, 2005, 10:10 AM
#2
Member
Re: Joining Tables From Diff Databases
If you're just going to do this only once you can use the OPENROWSET or OPENDATASOURCE look at your SQL Server Books Online regading these functions.
-
Aug 3rd, 2005, 10:12 AM
#3
Re: Joining Tables From Diff Databases
Should be possible. I have only ever done this from SQL Server to SQL Server. There are two methods.
Setup a Linked Server. Then you can use the 4 part name syntax to access the server.
Code:
Select *
From LocalTable L Left Join LinkedServerName.DataBaseName.OwnerName.TableName LS
On L.Id = LS.Id
Use the Ad-Hoc query methods - OpenRowset, OpenDataSource, OpenQuery
Code:
SELECT Stock.*, P.ProductName
FROM Stock
INNER JOIN OPENROWSET('SQLOLEDB','servername';'sa';'sapwd',
'SELECT ProductId, ProductName FROM Products') AS P
On Stock.ProductId = P.ProductId
-
Aug 3rd, 2005, 10:25 AM
#4
Re: Joining Tables From Diff Databases
 Originally Posted by brucevde
Should be possible. I have only ever done this from SQL Server to SQL Server. There are two methods.
Setup a Linked Server. Then you can use the 4 part name syntax to access the server.
Code:
Select *
From LocalTable L Left Join LinkedServerName.DataBaseName.OwnerName.TableName LS
On L.Id = LS.Id
Use the Ad-Hoc query methods - OpenRowset, OpenDataSource, OpenQuery
Code:
SELECT Stock.*, P.ProductName
FROM Stock
INNER JOIN OPENROWSET('SQLOLEDB','servername';'sa';'sapwd',
'SELECT ProductId, ProductName FROM Products') AS P
On Stock.ProductId = P.ProductId
Actualy, doesn't the Linked Server superceede the need to use the 4 part name? I've know I've gone from Server A to Server B using the 4 part harmony, with out a linked server.... I thought a Linked Server wasa "shortcut" of sorts, allowing you to LS.Table .... ?? but it's been a while, so I could be smoking something...
;P
Tg
-
Aug 3rd, 2005, 10:40 AM
#5
Re: Joining Tables From Diff Databases
You are smoking something again (and probably drinking too).
If you leave out the server name, SQL Server assumes the current server. But then again things change so fast, I am becoming obsolete (so says the junior prog at work - l'il *******)
-
Jan 4th, 2006, 03:36 PM
#6
Addicted Member
Re: Joining Tables From Diff Databases
how do you set up a linked server?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|