BookmarkSubscribeRSS Feed
LUISFELIPE10
Fluorite | Level 6

Boa tarde!

 

Prezados, alguém consegue ajudar na query abaixo:

A ideia e´ trazer apenas os registros dos últimos 30 dias, conforme o campo 

"WHERE DATEPART(NM_DATA_ANALISE) >= (DATE()- 30);"

 

Contudo, o resultado esta trazendo todo o período, como se não tivesse o filtro de data.

 

PROC SQL;
CREATE TABLE WORK.ANALISE_01 AS
SELECT
NR_SINISTRO,
NM_BANCO,
NM_PROCURADOR,
NM_AGENCIA,
NM_STATUS,
NM_DATA_ANALISE
FROM PESSOAL.NM_ANALISE;
WHERE DATEPART(NM_DATA_ANALISE) >= (DATE()- 30);
QUIT;

7 REPLIES 7
Tom
Super User Tom
Super User

Place the closing semicolon of a multiple line statement on its own line to avoid such confusion.

 

Google Translate:

Coloque o ponto e vírgula de fechamento de uma instrução de múltiplas linhas em sua própria linha para evitar tal confusão.

CREATE TABLE WORK.ANALISE_01 AS
SELECT
  NR_SINISTRO
, NM_BANCO
, NM_PROCURADOR
, NM_AGENCIA
, NM_STATUS
, NM_DATA_ANALISE
FROM PESSOAL.NM_ANALISE
WHERE DATEPART(NM_DATA_ANALISE) >= (DATE()- 30)
;
LUISFELIPE10
Fluorite | Level 6

Boa tarde!

Realmente tinha uma " ; " na frente do FROM de forma errada, descuido meu.

De qualquer forma, após a correção do script, rodou corretamente, porém não trouxe informações, o output veio vazio.

Cheguei a substituir o DATE por TODAY, porém não houve mudança.

Alguma ideia de como resolver essa questão?

 

PROC SQL;
CREATE TABLE WORK.ANALISE_01 AS
SELECT
NR_SINISTRO,
NM_BANCO,
NM_PROCURADOR,
NM_AGENCIA,
NM_STATUS,
NM_DATA_ANALISE
FROM PESSOAL.NM_ANALISE
WHERE
DATEPART(NM_DATA_ANALISE) >= (DATE() - 60);
QUIT;

 

LUISFELIPE10_0-1695840038403.png

 

PaigeMiller
Diamond | Level 26

If there is no output, then a possible solution is to remove the DATEPART function, as it might not be needed here.

 

Se não houver saída, uma solução possível é remover a função DATEPART, pois ela pode não ser necessária aqui.

 

 

--
Paige Miller
Kurt_Bremser
Super User

Are you sure that nm_data_analise is a datetime and not a date? Please run PROC CONTENTS and post the resulting output for that variable.

LUISFELIPE10
Fluorite | Level 6

Boa tarde!

Não é isso também.

A tabela esta´ correta e possui intervalo de datas dentro do filtro estipulado.

Cheguei a testar com 30, 60, 90, 120 dias para traz, porem não deu certo.

Eu imagino que seja alguma coisa referente ao tipo do campo, contudo, o mesmo esta tambem já no formato de data.

 

Tabela => FROM PESSOAL.NM_ANALISE

LUISFELIPE10_0-1695841187459.png

 

PaigeMiller
Diamond | Level 26

@LUISFELIPE10 wrote:

Boa tarde!

Não é isso também.

A tabela esta´ correta e possui intervalo de datas dentro do filtro estipulado.

Cheguei a testar com 30, 60, 90, 120 dias para traz, porem não deu certo.

Eu imagino que seja alguma coisa referente ao tipo do campo, contudo, o mesmo esta tambem já no formato de data.

 

Tabela => FROM PESSOAL.NM_ANALISE

LUISFELIPE10_0-1695841187459.png

 


I don't see any reason you need DATEPART, which will likely give the wrong answer. Did you try it without DATEPART?

 

By the way I agree with @Kurt_Bremser , show us the PROC CONTENTS output for this variable.

--
Paige Miller
LUISFELIPE10
Fluorite | Level 6

Boa tarde!

 

É exatamente isso, não havia necessidade de utilizar o DATEPART.

Não havia testado sem ele anteriormente.

Tirei ele da query e testei novamente e o resultado apareceu corretamente.

Muito obrigado pela ajuda.