Solved

VB6 and DBF files with outer joins

Posted on 2006-06-21
7
253 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
  • 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

785 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