Avatar of morrisbo
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

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
Microsoft AccessMicrosoft Legacy OSSQL

Avatar of undefined
Last Comment
morrisbo

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Rey Obrero (Capricorn1)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
morrisbo

ASKER
capricorn1

That worked - thanks for the quick solution

morrisbo
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck