create view vw_nfe_item_ipi
as
-- drop view vw_nfe_item_ipi
select	id_nfe	,
		i.id as id_item,
		nr_item ,
		ds_uf   ,
		case when p.tp_imposto = 'T' then '50'
			 when p.tp_imposto = 'N' then '53' 		  else '' end as tp_cst,
		case when p.tp_imposto = 'T' then vl_totalcom else 0  end as vl_BC   ,
        case when p.tp_imposto = 'T' then p.vp_IPI 	  else 0  end as 'vp_IPI'  ,
		case when p.tp_imposto = 'T' then (vl_totalcom / 100) else 0 end * vp_ipi  as vl_ipi
from    nfe_item i
join	nfe_produto_imposto p on i.id_produto = p.id_produto
order	by 1
;