Cross Server/Database Inner join?

I'm trying to cross join a query and it doesn't appear to by working:

SELECT Server1.DatabaseX.dbo.Table1.Field1, Server1.DatabaseX.dbo.Table1.Field2
FROM Server1.DatabaseX.dbo.Table1
INNER JOIN Server1.DatabaseX.dbo.Table1 ON
Server2.DatabaseY.dbo.Table1.Field1 = Server1.DatabaseX.dbo.Table1.Field1
WHERE (Server2.DatabaseY.dbo.Table1.Field1 = 1)

I keep getting an error telling me table "Server2.DatabaseY.dbo.Table1" does not exist -- but I can't see anything wrong in my SQL statement?

Rob.
 
RobAinscoughAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rafranciscoCommented:
I am not sure if it is just a typo but your second table should be Server2.DatabaseY.dbo.Table1:

SELECT Server1.DatabaseX.dbo.Table1.Field1, Server1.DatabaseX.dbo.Table1.Field2
FROM Server1.DatabaseX.dbo.Table1
INNER JOIN Server2.DatabaseY.dbo.Table1 ON
Server2.DatabaseY.dbo.Table1.Field1 = Server1.DatabaseX.dbo.Table1.Field1
WHERE (Server2.DatabaseY.dbo.Table1.Field1 = 1)

Aside from this, your query looks ok.
RobAinscoughAuthor Commented:
no typo, maybe that is my problem -- can you be more specific?

I'm selecting two fields from the same table (table1) in DatabaseX that are joined by Field1 in the other table (table1) in DatabaseY.
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I think rafrancisco pointed to this:

SELECT Server1.DatabaseX.dbo.Table1.Field1, Server1.DatabaseX.dbo.Table1.Field2
FROM Server1.DatabaseX.dbo.Table1
INNER JOIN Server1.DatabaseX.dbo.Table1 ON  <<<< here you JOIN to table on Server1 instead of Server 2
Server2.DatabaseY.dbo.Table1.Field1 = Server1.DatabaseX.dbo.Table1.Field1  <<< here you put JOIN CONDITION for Server 2
WHERE (Server2.DatabaseY.dbo.Table1.Field1 = 1)

updated version:
SELECT Server1.DatabaseX.dbo.Table1.Field1, Server1.DatabaseX.dbo.Table1.Field2
FROM Server1.DatabaseX.dbo.Table1
INNER JOIN Server2.DatabaseX.dbo.Table1
 ON Server2.DatabaseY.dbo.Table1.Field1 = Server1.DatabaseX.dbo.Table1.Field1
WHERE (Server2.DatabaseY.dbo.Table1.Field1 = 1)

Now, besides the syntax error I don't understand this

 ON Server2.DatabaseY.dbo.Table1.Field1 = Server1.DatabaseX.dbo.Table1.Field1
WHERE (Server2.DatabaseY.dbo.Table1.Field1 = 1) <<<<<

With this WHERE condition, you limit the rows to where Field1 has a value of 1, which is the same field used for joining the 2 tables...

Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

RobAinscoughAuthor Commented:
That didn't work, I get the following error:

"The number name 'Server1.DatabaseX.dbo.Table1' contains more than the maximum number of prefixes. The maximum is 3."

I thought SQL 2000 supported the format

ServerName.DatabaseName.Owner.TableName  ??
rafranciscoCommented:
Yes it does support that format.  What you have to do is use aliases for you tables, as follows:

SELECT A.Field1, A.Field2
FROM Server1.DatabaseX.dbo.Table1 A
INNER JOIN Server2.DatabaseY.dbo.Table1 B ON
B.Field1 = A.Field1
WHERE (B.Field1 = 1)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RobAinscoughAuthor Commented:
Nope, that didn't work.  A new error --

"Dynamic SQL generation is not supported against multiple base tables."


rafranciscoCommented:
Please post your latest query.
RobAinscoughAuthor Commented:
Oh, my fault -- I forgot to remove the GetUpdateCommand and GetInsertCommand -- being a read only type query I have no need for Dynamic SQL Generation for Update/Insert.

Tis working now -- Many thanks!!

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.