Fórum Achar total de dias utilizando SQL #455033

12/09/2013

0

Ola, para achar o total de dias entre a data do pedido e do faturamento é
select datediff(day,a.datped,getdate()) as tement, a.numped, a.valven, a.datped, a.datfat, a.codven, b.nomven
from ftd001 a, Arq004 b, Arq005 c
where a.datcan is null
and a.tippag = 4
and b.tipven = 'V'
and b.codven = a.codven
and c.tipdoc = 'R'
and c.codcli = a.codcli
and c.codven = a.codven
order by a.datped, c.codcli

o caso é como eu faço para achar o total de dias de de entrega de um pedido se o campo datfat que é data da fatura for nula?

obrigado
"Deus Abençoe"
Wilton Júnior

Wilton Júnior

Responder

Posts

12/09/2013

Wilton Júnior

'já achei um meio obrigado :)
Responder

Gostei + 0

12/09/2013

Joel Rodrigues

Poderia compartilhar conosco a solução encontrada?
Responder

Gostei + 0

13/09/2013

Wilton Júnior

Duas solucoes
select a.numped, a.valven, a.datped, a.datfat,
case
when (datfat is null) then
datediff(day,a.datped,getdate())
when (datfat is not null) then
datediff(day,a.datped,a.datfat)
end as tement
from ftd001 a, Arq005 b
where a.datcan is null
and a.tippag = 4
and b.tipdoc = 'R'
and b.codcli = a.codcli
and b.codven = a.codven
--and b.cliafa = 0
order by a.datped, b.codcli

ou
select a.numped, a.valven, a.datped, a.datfat,
if cxdateedit1.text = '' then
datediff(day,a.datped,getdate()) as tement
else
datediff(day,a.datped,a.datfat) as tement

from ftd001 a, Arq005 b
where a.datcan is null
and a.tippag = 4
and b.tipdoc = 'R'
and b.codcli = a.codcli
and b.codven = a.codven
--and b.cliafa = 0
order by a.datped, b.codcli
Responder

Gostei + 0

13/09/2013

Joel Rodrigues

Obrigado por compartilhar.
Estou marcando o tópico como concluído.
Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar