Solved

OPENQUERY INNER JOIN on two Remote Tables

Posted on 2004-10-06
3
6,698 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

707 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