Achar total de dias utilizando SQL
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"
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
Curtidas 0
Respostas
Wilton Júnior
12/09/2013
'já achei um meio obrigado :)
GOSTEI 0
Joel Rodrigues
12/09/2013
Poderia compartilhar conosco a solução encontrada?
GOSTEI 0
Wilton Júnior
12/09/2013
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
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
Joel Rodrigues
12/09/2013
Obrigado por compartilhar.
Estou marcando o tópico como concluído.
Estou marcando o tópico como concluído.
GOSTEI 0