我试图在MYSQL 5.6上使用ON DUPLICATE KEY UPDATE
处理三个表。此查询将抛出此消息:
错误代码:1054。未知列'
tborgexpdoc.intCodOrgExpDoc
'在 'field list
'
是否可以使用两个或更多表?
INSERT INTO tbconsumidor
select tbconsumidor.intCodConsumidor,
case when tbconsumidor.strNome = '' then null else left(tbconsumidor.strNome,100) end strNome,
case when tbconsumidor.strEndereco = '' then null else left(tbconsumidor.strEndereco,100) end strEndereco,
left(tbconsumidor.strNumero,8) strNumero,
case when tbconsumidor.strComplemento = '' then null else left(tbconsumidor.strComplemento,100) end strComplemento,
case when tbconsumidor.strBairro = '' then null else left(tbconsumidor.strBairro,100) end strBairro,
case when tbconsumidor.strCidade = '' then null else left(tbconsumidor.strCidade,100) end strCidade,
case when tbconsumidor.strUF = '' then null else left(tbconsumidor.strUF,2) end strUF,
case when ((tbconsumidor.strCEP) regexp '^[[:digit:]]+$') = 1 then mig_sindecgo0008.tbconsumidor.strCEP end strCEP,
case when tbconsumidor.strDDD = '' then null else left(tbconsumidor.strDDD,3) end strDDD,
case when tbconsumidor.strFone = '' then null else left(tbconsumidor.strFone,40) end strFone,
case when tbconsumidor.strEmail = '' then null else left(tbconsumidor.strEmail,100) end strEmail,
case when tbconsumidor.strRG = '' then null else left(tbconsumidor.strRG,40) end strRG,
case when tbconsumidor.strCPF = '' then null else replace(replace(replace(tbconsumidor.strCPF,'.',''),'-',''),'/','') end strCPF,
case when tbconsumidor.strOutroDoc = '' then null else left(tbconsumidor.strOutroDoc,20) end strOutroDoc,
tborgexpdoc.intCodOrgExpDoc as intCodOrgExpDoc,
case
when (replace(replace(replace(tbconsumidor.dtInclusao,'-',''),':',''),' ','') regexp '^[[:digit:]]+$') = 1
and tbconsumidor.dtInclusao > '0000-00-00 00:00:00'
then tbconsumidor.dtInclusao
else '1900-01-01 00:00:00'
end dtInclusao,
case
when (replace(replace(replace(tbconsumidor.dtAlteracao,'-',''),':',''),' ','') regexp '^[[:digit:]]+$') = 1
and tbconsumidor.dtAlteracao > '0000-00-00 00:00:00'
then tbconsumidor.dtAlteracao
else '1900-01-01 00:00:00'
end dtAlteracao,
case
when (replace(replace(replace(tbconsumidor.dtNascimento,'-',''),':',''),' ','') regexp '^[[:digit:]]+$') = 1
and tbconsumidor.dtNascimento > '0000-00-00'
then tbconsumidor.dtNascimento
else null
end dtNascimento,
tbconsumidor.intCodUsuarioCAD,
tbconsumidor.intCodUsuarioALT,
case when tbconsumidor.intDeficiente in (0,1) then tbconsumidor.intDeficiente else null end intDeficiente,
case when tbconsumidor.intGestante in (0,1) then tbconsumidor.intGestante else null end intGestante,
left(tbconsumidor.strSexo,1) strSexo,
tbestadocivil.intCodEstadoCivil,
case when tbconsumidor.strCodMunicipio in ('','0') then null else tbconsumidor.strCodMunicipio end strCodMunicipio,
case when tbconsumidor.strRGUf = '' then null else left(tbconsumidor.strRGUf,2) end strRGUf
from mig_sindecgo0008.tbconsumidor
left join tbestadocivil
on tbconsumidor.intCodEstadoCivil = tbestadocivil.intCodEstadoCivil
left join tborgexpdoc
on tbconsumidor.intCodOrgExpDoc = tborgexpdoc.intCodOrgExpDoc
ON DUPLICATE KEY UPDATE
tbconsumidor.intCodConsumidor = values(intCodConsumidor),
tbconsumidor.strNome = values(strNome),
tbconsumidor.strEndereco = values(strEndereco),
tbconsumidor.strNumero = values(strNumero),
tbconsumidor.strComplemento = values(strComplemento),
tbconsumidor.strBairro = values(strBairro),
tbconsumidor.strCidade = values(strCidade),
tbconsumidor.strUF = values(strUF),
tbconsumidor.strCEP = values(strCEP),
tbconsumidor.strDDD = values(strDDD),
tbconsumidor.strFone = values(strFone),
tbconsumidor.strEmail = values(strEmail),
tbconsumidor.strRG = values(strRG),
tbconsumidor.strCPF = values(strCPF),
tbconsumidor.strOutroDoc = values(strOutroDoc),
tborgexpdoc.intCodOrgExpDoc = values(intCodOrgExpDoc),
tbconsumidor.dtInclusao = values(dtInclusao),
tbconsumidor.dtAlteracao = values(dtAlteracao),
tbconsumidor.dtNascimento = values(dtNascimento),
tbconsumidor.intCodUsuarioCAD = values(intCodUsuarioCAD),
tbconsumidor.intCodUsuarioALT = values(intCodUsuarioCAD),
tbconsumidor.intDeficiente = values(intDeficiente),
tbconsumidor.intGestante = values(intGestante),
tbconsumidor.strSexo = values(strSexo),
tbestadocivil.intCodEstadoCivil = values(intCodEstadoCivil),
tbconsumidor.strCodMunicipio = values(strCodMunicipio),
tbconsumidor.strRGUf = values(strRGUf)