Solved

VB6 and DBF files with outer joins

Posted on 2006-06-21
7
251 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

705 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

18 Experts available now in Live!

Get 1:1 Help Now