Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB6 and DBF files with outer joins

Posted on 2006-06-21
7
Medium Priority
?
278 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 2000 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 Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

876 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