VBA ADODB:左连接
VBA ADODB: left join
你能解释一下如何在我的代码 ADODB 中执行左连接吗?实际上,我的代码中有一个内部连接,我不知道如何修改语法:
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')
感谢您的帮助
JOIN 在 SELECT 之后和 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'"
假设你有3张表,你需要创建一个子查询。如果您有 4 个表,您将不得不再创建一个子查询。
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
你能解释一下如何在我的代码 ADODB 中执行左连接吗?实际上,我的代码中有一个内部连接,我不知道如何修改语法:
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')
感谢您的帮助
JOIN 在 SELECT 之后和 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'"
假设你有3张表,你需要创建一个子查询。如果您有 4 个表,您将不得不再创建一个子查询。
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