Solved

VB6 and DBF files with outer joins

Posted on 2006-06-21
7
258 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
Technology Partners: 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

Technology Partners: 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!

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

751 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