Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Thiago_Justen_

Verificar valores duplicados na carga de dados

Pessoal,

Estou com uma dificuldade e gostaria de compartilhar com vocês.

Vejam o script abaixo:

DADOS_TEMP:

LOAD * Inline [

     ID,CHAVE_ACESSO

    1,10

    2,20

    3,15

    4,10

    5,20

    6,25

];

DADOS:

LOAD

*,

    If(Previous(CHAVE_ACESSO)=CHAVE_ACESSO,'Duplicado','OK') AS DUPLICADO

RESIDENT DADOS_TEMP;

DROP TABLE DADOS_TEMP;

Pois bem, imaginei que o campo "DUPLICADO" me apontaria os ID's 4 e 5 como "Duplicados", contudo não funcionou. Usei o Peek também ao invés do Previous e ainda assim nada.

Imagino que o Previous verifique o dado anterior somente (meio óbvia esta constatação) e o que eu gostaria era algo capaz de "varrer" a coluna de cima para baixo verificando a condição estabelecida.

Vocês sugerem criar um laço de repetição para isso? Como vocês fariam, mestres?

Abraços

Thiago Justen Teixeira Gonçalves
Farol BI
WhatsApp: 24 98152-1675
Skype: justen.thiago
Labels (2)
1 Solution

Accepted Solutions
Thiago_Justen_
Author

Pessoal,

Vejam se essa resolução seria uma boa:

DADOS_TEMP:

LOAD * Inline [

    ID,CHAVE_ACESSO

    1,10

    2,20

    3,15

    4,10

    5,20

    6,25

  

];

DADOS:

LOAD

*,

    If(Previous(CHAVE_ACESSO)=CHAVE_ACESSO,'Duplicado','OK') AS DUPLICADO

RESIDENT DADOS_TEMP Order By CHAVE_ACESSO ASC;

DROP TABLE DADOS_TEMP;

Pra esse script o Order By me ajudou...

Vocês resolveriam de outra forma?

Thiago Justen Teixeira Gonçalves
Farol BI
WhatsApp: 24 98152-1675
Skype: justen.thiago

View solution in original post

4 Replies
Thiago_Justen_
Author

Pessoal,

Vejam se essa resolução seria uma boa:

DADOS_TEMP:

LOAD * Inline [

    ID,CHAVE_ACESSO

    1,10

    2,20

    3,15

    4,10

    5,20

    6,25

  

];

DADOS:

LOAD

*,

    If(Previous(CHAVE_ACESSO)=CHAVE_ACESSO,'Duplicado','OK') AS DUPLICADO

RESIDENT DADOS_TEMP Order By CHAVE_ACESSO ASC;

DROP TABLE DADOS_TEMP;

Pra esse script o Order By me ajudou...

Vocês resolveriam de outra forma?

Thiago Justen Teixeira Gonçalves
Farol BI
WhatsApp: 24 98152-1675
Skype: justen.thiago
afurtado
Partner Ambassador/MVP
Partner Ambassador/MVP

Thiago,

QlikView x64 - [C__tmp_Chave.qvw_]---2018-01-03 22_20_26.png

faltou somente o ORDER BY


DADOS_TEMP:

LOAD * Inline [

ID,CHAVE_ACESSO

1,10

2,20

3,15

4,10

5,20

6,25

];


DADOS:

LOAD

  *,

  If(Previous(CHAVE_ACESSO)=CHAVE_ACESSO,'Duplicado','OK') AS DUPLICADO

RESIDENT DADOS_TEMP ORDER BY CHAVE_ACESSO;


DROP TABLE DADOS_TEMP;

furtado@farolbi.com.br
afurtado
Partner Ambassador/MVP
Partner Ambassador/MVP

outra forma seria usar o EXISTS().   Mas neste caso não pode ter ser lido antes por tabela temporária ou mesmo em outra tabela......


DADOS_TEMP:

LOAD

    *,

    if(Exists(CHAVE_ACESSO),'Duplicado','Ok')  as DUPLICADO   

Inline [

ID,CHAVE_ACESSO

1,10

2,20

3,15

4,10

5,20

6,25

];



QlikView x64 - [C__tmp_Chave.qvw_]---2018-01-03 22_28_27.png

furtado@farolbi.com.br
Thiago_Justen_
Author

Então mestre,  acabei resolvendo com o Order By, conforme acima. Mas gostei também da ideia do Exists.

Thiago Justen Teixeira Gonçalves
Farol BI
WhatsApp: 24 98152-1675
Skype: justen.thiago