Link to home
Create AccountLog in
Avatar of morrisbo

asked on

access 2000 sql question for select from clause using outer join

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


         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


         Name                                                  Type                                         Size

         TblPolicyID                                          Long Integer                             4
         TblAgencyID                                        Long Integer                             4
         TblInsuredID                                       Long Integer                             4
         TblCompanyID                                     Long Integer                            4
         TblPolicyTypeID                                   Long Integer                            4
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of morrisbo



That worked - thanks for the quick solution