Solved

VB6 and DBF files with outer joins

Posted on 2006-06-21
7
255 Views
Last Modified: 2010-04-07
I have the following query
SELECT SHMASTER.NUMBER,SHMSTINF.FAMCODE,SHFAMCOD.FAMDESC
FROM SHMASTER
LEFT OUTER JOIN SHMSTINF ON SHMASTER.NUMBER = SHMSTINF.NUMBER
LEFT OUTER JOIN SHFAMCOD ON SHMSTINF.FAMCODE = SHFAMCOD.FAMCODE
WHERE SHMASTER.NUMBER = 2

For some reason I cannot do 2 left outer joins.  Just to give you background SHMSTINF and SHFAMCODE are lookup tables, and for some records they may not have entries.  Which is why I'm using Left Outer Joins.  If I eliminate one of the left outer joins it works fine.  I was really hoping to not have to do this in seperate queries.

Here is the error I receive:
"Syntax error (missing operator) in query expression 'SHMASTER.NUMBER = SHMSTINF.NUMBER LEFT OUTER JOIN SHFAMCOD ON SHMSTINF.FAMCODE = SHFAMCOD.FAMCODE"

Thanks
Mark
0
Comment
Question by:cambridge-tech
[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
  • 4
  • 2
7 Comments
 
LVL 9

Expert Comment

by:pradapkumar
ID: 16957235
SELECT SHMASTER.NUMBER,SHMSTINF.FAMCODE,SHFAMCOD.FAMDESC
FROM SHMASTER,SHMSTINF,SHFAMCOD WHERE SHMASTER.NUMBER = SHMSTINF.NUMBER AND SHMSTINF.FAMCODE = SHFAMCOD.FAMCODE
AND SHMASTER.NUMBER = 2


HI TRY THE ABOVE AND GIVE ME FEEDBACK.
0
 

Author Comment

by:cambridge-tech
ID: 16959782
I do not return a row if there is no corresponding data in SHFAMCOD.  Some of the rows in SHMASTER do not have a record in the SHFAMCOD table.  I need to have a row returned regardless if there is an entry in the SHFAMCOD table.

0
 
LVL 30

Expert Comment

by:nmcdermaid
ID: 16964988
You might have more luck moving this to the database section.

What driver are you using to run that query? Is it an ODBC driver? Maybe it doesn't support two left outer joins or it supports a mongrel version of SQL.

The first step is deriving what SQL ~does~ work and step up from there.

-Does just one outer join work?

SELECT SHMASTER.NUMBER,SHMSTINF.FAMCODE,SHFAMCOD.FAMDESC
FROM SHMASTER
LEFT OUTER JOIN SHMSTINF ON SHMASTER.NUMBER = SHMSTINF.NUMBER
WHERE SHMASTER.NUMBER = 2

-Does it support the *= operator (I know this is the wrong way to do it but at least it well tell you what syntax the driver supports)

SELECT SHMASTER.NUMBER,SHMSTINF.FAMCODE,SHFAMCOD.FAMDESC
FROM SHMASTER, SHMSTINF
WHERE SHMASTER.NUMBER *= SHMSTINF.NUMBER
AND SHMASTER.NUMBER = 2


0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:cambridge-tech
ID: 16970634
One left outer does work.

Havent had a chance to trhy the *= yet.  BTW what does that do?


Thanks
Mark
0
 

Author Comment

by:cambridge-tech
ID: 16976504
I'm going to move this to the database group.  
0
 
LVL 30

Accepted Solution

by:
nmcdermaid earned 500 total points
ID: 16977587
*= is the old notation for an outer join.


Its not recommended for use any more because its ambiguous - it's in the where clause instead of the from clause.


I think your best bet is try and find some doco on that driver/database and see excactly what it does and doesn't support.

Another thing you can try is a subselect but again this may not be supported:


SELECT SHMASTER.NUMBER,S.FAMCODE,S.FAMDESC
FROM SHMASTER
LEFT OUTER JOIN
(SELECT * FROM SHFAMCOD INNER JOIN SHMSTINF ON SHMSTINF.FAMCODE = SHFAMCOD.FAMCODE) S
ON SHMASTER.NUMBER = S.NUMBER
WHERE SHMASTER.NUMBER = 2


This may or may not give you the data you're after but hopefully you get the idea of the syntax.
0
 

Author Comment

by:cambridge-tech
ID: 16979612
Thanks that worked perfectly.

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

749 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