Erro em calculo complexo no firebird
Esta menssagem de erro acontece quando tento executar esta query abaixo ja notei que quando deixo o calculo menos complexo funciona,
mas quando deixo assim que é o correto ele me tras este erro
mas quando deixo assim que é o correto ele me tras este erro
Integer overflow. The result of an integer operation caused the siginificant bit of the result to carry
Select
ip.it_id,
(select rtrim(chave) from gera_chavenfe(eest.cd_ibge, current_date, rtrim(emp.cad_cpfcnpj), 1, nf.nf_numero, nf.id_nfe, 55)) as nf_chave,
IP.it_quant * ip.it_valunit,
nf.nf_data,
tes.tes_aliq_icm,
tes.tes_aliq_Pis,
tes.tes_aliq_cofins,
tes.tes_reduc_icms,
case
when tes.tdt_id = 2 then
case
when tes.tes_reduc_icms > 0 then
case
when ped.ped_val_unitario <= tbp.tbp_valor then
(((IP.it_quant * tbp.tbp_valor) * (tes.tes_reduc_icms/100))
* (tes_aliq_icm/100))
when ped.ped_val_unitario > tbp.tbp_valor then
(((IP.it_quant * ped.ped_val_unitario) * (tes.tes_reduc_icms/100))
* (tes_aliq_icm/100))
end
end
end as valor_icms,
tes.tes_reduc_pis,
tes.tes_reduc_cofi,
ip.it_quant,
ped.prod_id,
tes.tdt_id,
tes.tes_aliq_ipi,
(ip.it_quant/1000) * ped.ped_val_frete,
ip.it_valunit,
ip.it_quant,
tes.tes_reduc_ipi,
tes.tes_fethab,
ped.ped_tipo_frete,
COALESCE(PED.ped_dias, 1),
cli.cad_tipopessoa,
case
when (cli.cad_tipopessoa = 'F' and tes.tes_fethab = 'S') then
(SELECT (ITP.it_quant /1000)*
(SELECT COALESCE(TBP.tbp_valor, 0)
FROM tb_pautas TBP
WHERE :data BETWEEN TBP.tbp_inicio AND TBP.tbp_final
AND TBP.id_imposto = 3
and tbp.prod_id = ped.prod_id
and tbp.tbp_tipo = ped.ped_tipo_frete)
FROM itens_ped ITP WHERE ITP.it_id = ip.it_id)
end as vl_fethab
from itens_ped ip
inner join tb_nfe nf on (nf.id_nfe = ip.nf_numero)
inner join pedido ped on (ped.ped_id = nf.id_ped)
inner join cadastros emp on (emp.id = ped.ped_emp)
inner join estado eest on (eest.est_codigo = emp.est_codigo)
inner join tab_tes tes on (tes.tes_id = ped.tes_id)
inner join cadastros cli on (cli.id = ped.ped_cliente)
inner join tb_pautas tbp on (tbp.prod_id = ped.prod_id and tbp.id_imposto = 1 and tbp.tbp_tipo = ped.ped_tipo_frete)
where nf.id_nfe = :id_nfe
and nf.nf_data_emisao between tbp.tbp_inicio and tbp.tbp_final
Americo Neto
Curtidas 0
Respostas
Americo Neto
11/02/2015
resolvi transformando os valores inteiros em float segue o codigo abaixo
Select
ip.it_id,
(select rtrim(chave) from gera_chavenfe(eest.cd_ibge, current_date, rtrim(emp.cad_cpfcnpj), 1, nf.nf_numero, nf.id_nfe, 55)) as nf_chave,
IP.it_quant * ip.it_valunit,
nf.nf_data,
tes.tes_aliq_icm,
tes.tes_aliq_Pis,
tes.tes_aliq_cofins,
tes.tes_reduc_icms,
case
when tes.tdt_id = 2 then
case
when tes.tes_reduc_icms > 0 then
case
when ped.ped_val_unitario <= tbp.tbp_valor then
(((IP.it_quant * tbp.tbp_valor) * (tes.tes_reduc_icms/ cast(100 as float)))
* (tes_aliq_icm/cast(100 as float)))
when ped.ped_val_unitario > tbp.tbp_valor then
(((IP.it_quant * ped.ped_val_unitario) * (tes.tes_reduc_icms/cast(100 as float)))
* (tes_aliq_icm/cast(100 as float)))
end
end
end as valor_icms,
tes.tes_reduc_pis,
tes.tes_reduc_cofi,
ip.it_quant,
ped.prod_id,
tes.tdt_id,
tes.tes_aliq_ipi,
(ip.it_quant/1000) * ped.ped_val_frete,
ip.it_valunit,
ip.it_quant,
tes.tes_reduc_ipi,
tes.tes_fethab,
ped.ped_tipo_frete,
COALESCE(PED.ped_dias, 1),
cli.cad_tipopessoa,
case
when (cli.cad_tipopessoa = 'F' and tes.tes_fethab = 'S') then
(SELECT (ITP.it_quant /1000)*
(SELECT COALESCE(TBP.tbp_valor, 0)
FROM tb_pautas TBP
WHERE :data BETWEEN TBP.tbp_inicio AND TBP.tbp_final
AND TBP.id_imposto = 3
and tbp.prod_id = ped.prod_id
and tbp.tbp_tipo = ped.ped_tipo_frete)
FROM itens_ped ITP WHERE ITP.it_id = ip.it_id)
end as vl_fethab
from itens_ped ip
inner join tb_nfe nf on (nf.id_nfe = ip.nf_numero)
inner join pedido ped on (ped.ped_id = nf.id_ped)
inner join cadastros emp on (emp.id = ped.ped_emp)
inner join estado eest on (eest.est_codigo = emp.est_codigo)
inner join tab_tes tes on (tes.tes_id = ped.tes_id)
inner join cadastros cli on (cli.id = ped.ped_cliente)
inner join tb_pautas tbp on (tbp.prod_id = ped.prod_id and tbp.id_imposto = 1 and tbp.tbp_tipo = ped.ped_tipo_frete)
where nf.id_nfe = :id_nfe
and nf.nf_data_emisao between tbp.tbp_inicio and tbp.tbp_finalGOSTEI 0