1

I have SQL Activy below and some days ago happens the errored:

Query failed during execution. Error: Violation of PRIMARY KEY constraint. Cannot insert duplicate key in object 'Clientes_RDB'. The duplicate key value is (0011I00000tUzJsQAK).

Select distinct
(cp.IdConta) as IdConta,
  a.FirstName as Nome,
  a.LastName as Sobrenome,
  a.TW1_Sexo__c as Genero,
  a.Phone as Telefone,
  a.PersonMobilePhone as Celular,
  a.PersonEmail as Email,
  a.TW1_Av_Rua__c as Av_Rua,
  a.TW1_Bairro__c as Bairro,
  a.TW1_Complemento__c as Complemento,
  a.TW1_Cidade__c as Cidade,
  a.TW1_UF__c as Estado,
  a.TW1_Pais__c as País,
  a.CEP__c as CEP,
  a.TW1_CPF__c as CPF,
  a.TW1_Identidade__c as Identidade,
  a.TW1_Data_Nascimento__c as DataNascimento,
  Day(a.TW1_Data_Nascimento__c) as Aniversario_Dia,
  Case
    When
      Month(a.TW1_Data_Nascimento__c) = 1 
    then
      'Janeiro' 
    When
      Month(a.TW1_Data_Nascimento__c) = 2 
    then
      'Fevereiro' 
    When
      Month(a.TW1_Data_Nascimento__c) = 3 
    then
      'Março' 
    When
      Month(a.TW1_Data_Nascimento__c) = 4 
    then
      'Abril' 
    When
      Month(a.TW1_Data_Nascimento__c) = 5 
    then
      'Maio' 
    When
      Month(a.TW1_Data_Nascimento__c) = 6 
    then
      'Junho' 
    When
      Month(a.TW1_Data_Nascimento__c) = 7 
    then
      'Julho' 
    When
      Month(a.TW1_Data_Nascimento__c) = 8 
    then
      'Agosto' 
    When
      Month(a.TW1_Data_Nascimento__c) = 9 
    then
      'Setembro' 
    When
      Month(a.TW1_Data_Nascimento__c) = 10 
    then
      'Outubro' 
    When
      Month(a.TW1_Data_Nascimento__c) = 11 
    then
      'Novembro' 
    When
      Month(a.TW1_Data_Nascimento__c) = 12 
    then
      'Dezembro' 
  end
  as Aniversario_Mes, Year(a.TW1_Data_Nascimento__c) as Aniversario_Ano, a.TW1_Estado_civil__c as EstadoCivil, 
  (
    Select
      r.Name 
    from
      RECORDTYPE_SALESFORCE r 
    Where
      r.Id = a.RecordTypeId
  )
  as Tipo_de_Conta,
  a.CreatedDate as Data_de_criacao,
  Origem as Origem,
  DataAtividade as DataVinculo 
From
  (
    select
      c.IdConta,
      c.Id,
      Origem,
      c.DataAtividade 
    from
      Contas_RDB c 
      Inner join
        (
          Select
            Min(DataAtividade) as DataAtividade,
            IdConta 
          from
            Contas_RDB 
          group by
            IdConta 
        )
        Ac 
        on C.IdConta = Ac.IdConta 
        and C.DataAtividade = Ac.DataAtividade
  )
  cp 
  Join
    ACCOUNT_SALESFORCE a 
    On cp.idConta = a.id
1

I'm assuming that Clientes_RDB is set as the only primary key column in your target data extension.

You are trying to insert a row where the value for Clientes_RDB already matches an existing row in your data extension, so this record is unable to be inserted. You can either amend your data action type, or you can add additional columns to your primary/composite key that will uniquely identify the new row as a unique one in the table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.