Fórum Achar total de dias utilizando SQL #455033
12/09/2013
0
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
Curtir tópico
+ 0Posts
12/09/2013
Wilton Júnior
Gostei + 0
12/09/2013
Joel Rodrigues
Gostei + 0
13/09/2013
Wilton Júnior
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
Gostei + 0
13/09/2013
Joel Rodrigues
Estou marcando o tópico como concluído.
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)