Solved

access 2000 sql question for select from clause using outer join

Posted on 2013-12-30
2
409 Views
Last Modified: 2013-12-30
I am having a problem with an access 2000 sql query using two tables and an outer join.
This sql statement is from within a VB6 program.

I am getting a syntax error in the FROM clause.

See sql statements below.

When I change the OUTER LEFT JOIN clause to INNER JOIN, I do not get the syntax error, but I chose the OUTER JOIN because I want the records from the TblInsured whether there are corresponding  TblPolicy records or not. It is my understanding that the INNER JOIN will only return records if there is a match with the TblInsuredID in both tables. There are Insureds with no policy records, i.e. no policy records where TblInsuredID matches TblInsuredID in an Insured record.



=======================================================================

sSelect = "SELECT TblInsured.*, TblPolicy.* "

sfrom = "FROM TblInsured OUTER LEFT JOIN TblPolicy on TblInsured.TblInsuredID = TblPolicy.TblInsuredID "

sWhere = "WHERE (((Account_Type)=" & bu & " Or (Account_Type)=" & pe & " Or " _
& "(Account_Type)=" & PR & ") AND ((Account_Status)=" & Chr(39) & incl & Chr(39) & " Or " _
& "(Account_Status)=" & Chr(39) & excl & Chr(39) & ") AND ((Insured_Name2)>=" & Chr(39) & n1 & Chr(39) & " And " _
& "(Insured_Name2)<=" & Chr(39) & n2 & Chr(39) & ")) "
   
sOrder = "ORDER BY Insured_Name2, Insured_Name; "

sSQL$ = sSelect & sfrom & sWhere & sOrder

rs.Open sSQL, Conn, adOpenStatic, adLockPessimistic, adCmdText
---------------------------------------------------------------------
The ERROR MESSAGE is when rs.Open statement above is executed.
----------------------------------------------------------------------------------------------------
Syntax error in FROM clause. in ProcessRecordsCustomersLocation Procedure
----------------------------------------------------------------------------------------------------

when I change the sFrom statement wording from OUTER LEFT JOIN to INNER JOIN the action works, i.e. no Systax error. If I just remove the LEFT qualifier from the OUTER JOIN I still get the syntax error.

The data base is Access2000.  Procedure is in a VB6 program

Thanks for any assistance with this problem.

--------------------------------------------------------------------------------------------------------------

Table: TblInsured                                                                                    Page: 1

Columns

         Name                                                     Type                                         Size

         TblInsuredID                                          Long Integer                             4
         TblAgencyID                                           Long Integer                             4
         TblLocationID                                         Long Integer                             4
         TblUserID                                               Text                                        20
         Account_Number                                    Text                                       20
--------------------------------------------------------------------------------------------------------------

Table: TblPolicy                                                                                     Page: 1

Columns

         Name                                                  Type                                         Size

         TblPolicyID                                          Long Integer                             4
         TblAgencyID                                        Long Integer                             4
         TblInsuredID                                       Long Integer                             4
         TblCompanyID                                     Long Integer                            4
         TblPolicyTypeID                                   Long Integer                            4
0
Comment
Question by:morrisbo
2 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
try using  LEFT JOIN only

sfrom = "FROM TblInsured LEFT JOIN TblPolicy on TblInsured.TblInsuredID = TblPolicy.TblInsuredID "
0
 

Author Closing Comment

by:morrisbo
Comment Utility
capricorn1

That worked - thanks for the quick solution

morrisbo
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

772 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

11 Experts available now in Live!

Get 1:1 Help Now