VBA_Anne_Marie
VBA_Anne_Marie

Reputation: 373

VBA ADODB: left join

Could you explain me please how to performe the left join in my code ADODB. Actually, I have a inner join in my code, I don't know how to modify the syntax :

Public Sub SUPP_D_ATTENTE(NO_POLICE As String)
Dim RECSET As New ADODB.Recordset
RECSET.Open "select  sousc.lp_etat_doss as cd_rga from db_dossier sousc, db_personne pers, db_garantie gar, db_ctrat_support ctrats, db_param_mandat_op mandaop, db_rga rga" & _
            " where sousc.no_police = '" & NO_POLICE & "' and sousc.cd_dossier = 'SOUSC' and sousc.lp_etat_doss not in ('ANNUL','A30','IMPAY') 

Thank you for your help

Upvotes: 0

Views: 1228

Answers (2)

Dy.Lee
Dy.Lee

Reputation: 7567

Assuming you have 3 tables, you need to create a subquery. If you have 4 tables, you will have to create one more subquery.

tableA, tableB, tableC

select c.field1, c.field2, d.field1, d.field2 from
    ( select a.field1 as field1, b.field2 as field2 from
        ( select * from tableA where field1 = 'aaa' and field2 ='123') as a left join tableB as b
        on a.field1= b.field1
     ) as c
left join tableC as d 
on c.field2 = d.field2

Upvotes: 0

CDP1802
CDP1802

Reputation: 16224

The JOIN comes after the SELECT and before the WHERE

 " SELECT sousc.lp_etat_doss as cd_rga" & _
 " FROM db_dossier sousc" & _
 
 " LEFT JOIN db_garantie gar" & _
 "   ON gar.is_protocole = sousc.is_protocole" & _
   
 " WHERE sousc.no_police = '" & NO_POLICE & "'" & _
 "   AND sousc.cd_dossier = 'SOUSC'" & _
 "   AND sousc.lp_etat_doss NOT IN ('ANNUL','A30','IMPAY')" & _ 
 "   AND gar.cd_garantie  = 'DEDIE'"

Upvotes: 1

Related Questions