Aviso: Este artigo ainda é um rascunho!
TV_LUC por período pela descrição DESMAT
select * from tv_luc where (codfil,filmat,codmat,codcor,codtam,codmul) in (select '004',g.filmat,g.codmat,g.codcor,g.codtam,0 from tt_gra g, tt_pro p where p.filmat = g.filmat and p.codmat = g.codmat and p.desmat = upper('almofada n3 carbex')) and dathor between to_date('010404','DDMMYY') and to_date('010404235959','DDMMYYHH24MISS')
Custo de Reposição da Filial pela descrição DESMAT na data especificada
Igual para CustoReposicaoData, CustoFreteData e CustoCompraData
select CustoReposicaoData( to_date('010404','DDMMYY'), FILMAT, CODMAT, CODCOR, CODTAM, CODFIL, 0 ) from (select '004' CODFIL, g.filmat,g.codmat,g.codcor,g.codtam from tt_gra g, tt_pro p where p.filmat = g.filmat and p.codmat = g.codmat and p.desmat = upper('almofada n3 carbex'))
Custo de reposição x vlr/qtd na TT_ICO por período pela descrição DESMAT
select cusrep,vlrmov/qtdmov, ico.* from tt_ico ico where (codfil,filmat,codmat,codcor,codtam) in (select '004',g.filmat,g.codmat,g.codcor,g.codtam from tt_gra g, tt_pro p where p.filmat = g.filmat and p.codmat = g.codmat and p.desmat = upper('almofada n3 carbex')) and com_datope between to_date('011103','DDMMYY') and to_date('010404235959','DDMMYYHH24MISS')
Para agilizar sub-selects por filial pelo DESMAT sem usar TV_IPR
select '004' codfil,g.filmat,g.codmat,g.codcor,g.codtam,0 codmul from tt_gra g, tt_pro p where p.filmat = g.filmat and p.codmat = g.codmat and p.desmat = upper('alcool 1lt')
Traz itens de compra mais recentes que possuem frete mas não foi calculado CUSFRE
select * from tt_ico where nvl(cusfre,0) = 0 and (codfil,sequen) in ( select codfil,sequen from tt_com where tippar = 'F' and seqfre is not null) order by com_datope desc