CPF Validation - Integration Services

Asked

Viewed 424 times

1

I am importing a base with Cpfs for my DW but need to do CPF validation inside SSIS.

Does anyone have any idea how I can do that?

Thank you!


Edit:

I got it done the way I wanted it.

I used the Component script, I took a validation code in c#.

Got that way inserir a descrição da imagem aqui

  • 1

    You want to know if a given number obeys the CPF training rule or if this number, in addition to obeying the training rule, is registered in the revenue database as a valid CPF?

  • I want to know if he is a valid CPF according to the revenue base

  • Then you will have to consult the IRS database. The consultation to the Cadastral Situation will give you this information. What I don’t know is if there’s some kind of free web service for that.

1 answer

1

You can use a SQL Server function ?

/*
  Cristiano Martins Alves
  Para testar: SELECT DBO.CPF_VALIDO('16195473247')
*/
CREATE FUNCTION CPF_VALIDO(@CPF VARCHAR(11))
RETURNS CHAR(1)
AS
BEGIN
  DECLARE @INDICE INT,
          @SOMA INT,
          @DIG1 INT,
          @DIG2 INT,
          @CPF_TEMP VARCHAR(11),
          @DIGITOS_IGUAIS CHAR(1),
          @RESULTADO CHAR(1)

  SET @RESULTADO = 'N'

  /*
      Verificando se os digitos são iguais
      A Principio CPF com todos o números iguais são Inválidos
      apesar de validar o Calculo do digito verificado
      EX: O CPF 00000000000 é inválido, mas pelo calculo
      Validaria
  */

  SET @CPF_TEMP = SUBSTRING(@CPF,1,1)

  SET @INDICE = 1
  SET @DIGITOS_IGUAIS = 'S'

  WHILE (@INDICE <= 11)
  BEGIN
    IF SUBSTRING(@CPF,@INDICE,1) <> @CPF_TEMP
      SET @DIGITOS_IGUAIS = 'N'
    SET @INDICE = @INDICE + 1
  END;

  --Caso os digitos não sejão todos iguais Começo o calculo do digitos
  IF @DIGITOS_IGUAIS = 'N' 
  BEGIN
    --Cálculo do 1º dígito
    SET @SOMA = 0
    SET @INDICE = 1
    WHILE (@INDICE <= 9)
    BEGIN
      SET @Soma = @Soma + CONVERT(INT,SUBSTRING(@CPF,@INDICE,1)) * (11 - @INDICE);
      SET @INDICE = @INDICE + 1
    END

    SET @DIG1 = 11 - (@SOMA % 11)

    IF @DIG1 > 9
      SET @DIG1 = 0;

    -- Cálculo do 2º dígito }
    SET @SOMA = 0
    SET @INDICE = 1
    WHILE (@INDICE <= 10)
    BEGIN
      SET @Soma = @Soma + CONVERT(INT,SUBSTRING(@CPF,@INDICE,1)) * (12 - @INDICE);
      SET @INDICE = @INDICE + 1
    END

    SET @DIG2 = 11 - (@SOMA % 11)

    IF @DIG2 > 9
      SET @DIG2 = 0;

    -- Validando
    IF (@DIG1 = SUBSTRING(@CPF,LEN(@CPF)-1,1)) AND (@DIG2 = SUBSTRING(@CPF,LEN(@CPF),1))
      SET @RESULTADO = 'S'
    ELSE
      SET @RESULTADO = 'N'
  END
  RETURN @RESULTADO
END

source: http://www.devmedia.com.br/funcao-para-validar-cpf-no-sql-server/2723

  • In vdd, I need to use some component that does the validation. As the conditional split, q ai the valid cpfs I will insert in the table and the invalid ones I will generate an output.

  • then just use the function... no ?

  • The way I wanted to do it I thought it best to use the Component script

  • cool, you managed to validate it also on the basis of the recipe ?

  • I used a C# script that validates the validation. Which is ultimately the same logic as your script

  • In the comment of your question, you say that validates by the revenue base, the validation of the code I posted, is by the check digit. Can you validate by revenue base ? IE, know if the CPF is active in the IRS ?

  • When I said that valid by the base of the Revenue is to know if it is a CPF that really exists. I think there has been a confusion in this concept. Whether he’s active or not wasn’t my goal.

  • Okay, but just to warn you that this logic of the checker digit only tells you if the number has the format of the CPF, still, it might not exist, okay? rsrs good luck =]

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.