Solved

OPENQUERY INNER JOIN on two Remote Tables

Posted on 2004-10-06
3
5,592 Views
Last Modified: 2008-01-09
I have two remote tables where I need have an INNER JOIN with OPENQUERY

This is what I want to do in regular SQL without OPENQUERY

SELECT * FROM hmodta.hmembp AS a
INNER JOIN mcnet..user_header AS p
ON a.SUBNO+a.PERNO = p.ExternalSystemKey
ORDER BY a.SUBNO DESC

Here is what I have for OPENQUERY.  The 2 remote servers are AS400 and WEBSRVR

SELECT * FROM
OpenQuery(AS400, 'SELECT * FROM hmodta.hmembp AS a INNER JOIN')
OpenQuery(WEBSRVR2, 'mcnet..user_header AS p ON a.SUBNO concat a.PERNO = p.ExternalSystemKey ORDER BY a.SUBNO DESC')

I know this isn't right, but could someone give me assistance?  Thanks in advance

0
Comment
Question by:vikingg97
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
miron earned 500 total points
ID: 12242416
SELECT * FROM
OpenQuery(AS400, 'SELECT * FROM hmodta.hmembp')  as a INNER JOIN
OpenQuery(WEBSRVR2, 'mcnet..user_header')  AS p ON a.SUBNO concat a.PERNO = p.ExternalSystemKey ORDER BY a.SUBNO DESC
0
 
LVL 1

Author Comment

by:vikingg97
ID: 12242600
I needed to modify it a little to narrow the results, so here is what I did and the error I get. Do I need to do something different?

SELECT * FROM
OpenQuery(AS400, 'SELECT * FROM hmodta.hmembp')  as a INNER JOIN
OpenQuery(WEBSRVR2, 'mcnet..user_header')  AS p ON a.SUBNO + a.PERNO = p.External_System_Key  
WHERE a.cgrpid = 'S0038A'
ORDER BY a.SUBNO DESC

Error:
Server: Msg 2809, Level 18, State 1, Line 1
The request for procedure 'User_Header' failed because 'User_Header' is a table object.

0
 
LVL 1

Author Comment

by:vikingg97
ID: 12243083
Nevermind I figured it out. I needed to change it to this.  Also narrow down the fields.

Thanks for setting it up miron.

Solution:
SELECT * FROM
OpenQuery(AS400, 'SELECT SUBNO, PERNO, cgrpid FROM hmodta.hmembp') as a INNER JOIN
OpenQuery(WEBSRVR2, 'SELECT External_System_Key, User_ID FROM mcnet..user_header')  AS p ON a.SUBNO + a.PERNO = p.External_System_Key  
WHERE a.cgrpid = 'M00005'
ORDER BY a.SUBNO DESC
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Suggested Solutions

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now