Usuário com melhor resposta
Select

Pergunta
-
Bom dia,
alguém poderia ajudar no select abaixo?
Eu preciso que retorne os campos de tal forma que max(D.cod_PE_Data_Limite) não seja maior @cod_PE_Data_Limite
@cod_PE_Data_Limite AS INT
select C.nome, B.nome_Comercial, max(D.cod_PE_Data_Limite) from PE B, Cadastro_Agente C, PE_Visita_Quinzenal D where B.inativo=0 and D.cod_PE=B.id and C.id=B.cod_Agente and B.id not in (select A.cod_PE from PE_Visita_Quinzenal A where A.cod_PE_Data_Limite=@cod_PE_Data_Limite ) group by B.nome_Comercial,C.nome
Respostas
-
Deleted
- Marcado como Resposta Wilson Boris quarta-feira, 25 de julho de 2018 13:44
Todas as Respostas
-
-
Obrigado pelo retorno José, você sempre em pronta resposta.
no codigo abaixo retornou com a mensagem:
Mensagem 4104, Nível 16, Estado 1, Linha 3
The multi-part identifier "B.cod_Agente" could not be bound.
Mensagem 4104, Nível 16, Estado 1, Linha 4
The multi-part identifier "B.id" could not be bound.SELECT C.nome, B.nome_Comercial, max(D.cod_PE_Data_Limite) from PE as B, Cadastro_Agente as C inner join PE_Visita_Quinzenal as D on C.id = B.cod_Agente and D.cod_PE = B.id where B.inativo = 0 and B.id not in (SELECT A.cod_PE from PE_Visita_Quinzenal A where A.cod_PE_Data_Limite=37 ) group by B.nome_Comercial, C.nome having max(D.cod_PE_Data_Limite) < 37;
No entanto, tentei com codigo abaixo e retronou certinho, pode ser?
select C.nome, B.nome_Comercial, max(D.cod_PE_Data_Limite) from PE B, Cadastro_Agente C, PE_Visita_Quinzenal D where B.inativo=0 and D.cod_PE=B.id and C.id=B.cod_Agente and B.id not in (select A.cod_PE from PE_Visita_Quinzenal A where A.cod_PE_Data_Limite=37) group by B.nome_Comercial, C.nome having max(D.cod_PE_Data_Limite) < 37
-
Deleted
- Marcado como Resposta Wilson Boris quarta-feira, 25 de julho de 2018 13:44