› Fóruns › SQL e PL/SQL › Select em 3 tabelas e update em 1 delas › Select em 3 tabelas e update em 1 delas
Codigo para consulta
select A.Item_Estoque, C.Numero_Nota_Fiscal, B.Quantidade, A.Base_Pis, A.Base_Cofins, C.Dta_Entrada_Saida from pec_item_estoque A, fat_movimento_item B, fat_movimento_capa C
where posicao_fiscal = 40169990
and C.dta_entrada_saida between to_date(’12/08/2013′,’dd/mm/yyyy’)
and to_date(’12/08/2013′,’dd/mm/yyyy’)
and C.revenda = 1
and A.item_estoque = B.Item_Estoque
and B.Numero_Nota_Fiscal = C.NUMERO_NOTA_FISCAL
and C.Tipo_Transacao = ‘P01’
order by C.Numero_Nota_Fiscal
Retorna os valores abaixo:
Item_estoque Num_nota QTD Base_Pis Base_Con DTA_Entrada
1 53513 102032 1,00 0,00 0,00 12/08/2013
2 64034 102118 3,00 100,00 100,00 12/08/2013
3 31025 1744962 2,00 0,00 0,00 12/08/2013
4 31025 1744962 2,00 0,00 0,00 12/08/2013
5 65056 1745438 1,00 0,00 0,00 12/08/2013
6 65056 1745438 1,00 0,00 0,00 12/08/2013
Codigo do com update:
update pec_item_estoque A
set A.base_pis = ‘0,00’
where A.posicao_fiscal in
(select A.Item_Estoque from pec_item_estoque A, fat_movimento_item B, fat_movimento_capa C
where posicao_fiscal = 40169990
and C.dta_entrada_saida between to_date(’12/08/2013′,’dd/mm/yyyy’)
and to_date(’12/08/2013′,’dd/mm/yyyy’)
and C.revenda = 1
and A.item_estoque = B.Item_Estoque
and B.Numero_Nota_Fiscal = C.NUMERO_NOTA_FISCAL
and C.Tipo_Transacao = ‘P01’)