ROMANVPP Posted August 5, 2011 Report Share Posted August 5, 2011 Pessoal,Alguém sabe como fazer um update em uma query como essa? No caso preciso atualizar apenas o campo "natrec".select distinct dl.docini,dl.seriedoc,dl.idlaf,dl.dataemissao,di.idprd,tp.descricao,dic.natrec,dti.sittributaria from dlaf dl inner join ditem di on (di.idlaf = dl.idlaf)left join ditemcompl dic on (dic.idlaf = di.idlaf and di.numitem = dic.numitem)inner join tprd tp on (tp.idprd = di.idprd)inner join dtrbitem dti on (dti.idlaf = di.idlaf and dti.numitem = di.numitem)where tp.descricao like '%arroz%' and dl.tipolf = 'S'and dl.dataemissao >= '2011/07/01' and dl.dataemissao <= '2011/07/31'and dti.sittributaria in ('04','06')and dl.seriedoc in ('1','ECF') and dic.natrec is nullorder by tp.descricaoTentei dessa forma mas não funciona (não pega todos os registros que preciso):update ditemcompl set natrec = '105'from ditemcompl dic inner join ditem di on (dic.idlaf = di.idlaf and di.numitem = dic.numitem)inner join dlaf dl on (di.idlaf = dl.idlaf)inner join tprd tp on (tp.idprd = di.idprd)inner join dtrbitem dti on (dti.idlaf = di.idlaf and dti.numitem = di.numitem)where tp.descricao like '%arroz%' and dl.tipolf = 'S'and dl.dataemissao >= '2011/07/01' and dl.dataemissao <= '2011/07/31'and dti.sittributaria in ('04','06')and dl.seriedoc in ('1','ECF') and dic.natrec is nullSe alguém puder ajudar fico grato Quote Link to comment Share on other sites More sharing options...
0 NIK Posted August 8, 2011 Report Share Posted August 8, 2011 Se você chamou a tabela de dic, tem que fazer o update por ela... Tente assim...update dic set natrec = '105'from ditemcompl dic inner join ditem di on (dic.idlaf = di.idlaf and di.numitem = dic.numitem)inner join dlaf dl on (di.idlaf = dl.idlaf)inner join tprd tp on (tp.idprd = di.idprd)inner join dtrbitem dti on (dti.idlaf = di.idlaf and dti.numitem = di.numitem)where tp.descricao like '%arroz%' and dl.tipolf = 'S'and dl.dataemissao >= '2011/07/01' and dl.dataemissao <= '2011/07/31'and dti.sittributaria in ('04','06')and dl.seriedoc in ('1','ECF') and dic.natrec is nullCaso de algum erro, escreve aqui pra gente.NIK Quote Link to comment Share on other sites More sharing options...
Question
ROMANVPP
Pessoal,
Alguém sabe como fazer um update em uma query como essa? No caso preciso atualizar apenas o campo "natrec".
select distinct dl.docini,dl.seriedoc,dl.idlaf,dl.dataemissao,di.idprd,tp.descricao,dic.natrec,dti.sittributaria from dlaf dl
inner join ditem di on (di.idlaf = dl.idlaf)
left join ditemcompl dic on (dic.idlaf = di.idlaf and di.numitem = dic.numitem)
inner join tprd tp on (tp.idprd = di.idprd)
inner join dtrbitem dti on (dti.idlaf = di.idlaf and dti.numitem = di.numitem)
where tp.descricao like '%arroz%' and dl.tipolf = 'S'
and dl.dataemissao >= '2011/07/01' and dl.dataemissao <= '2011/07/31'
and dti.sittributaria in ('04','06')
and dl.seriedoc in ('1','ECF') and dic.natrec is null
order by tp.descricao
Tentei dessa forma mas não funciona (não pega todos os registros que preciso):
update ditemcompl set natrec = '105'
from ditemcompl dic inner join ditem di on (dic.idlaf = di.idlaf and di.numitem = dic.numitem)
inner join dlaf dl on (di.idlaf = dl.idlaf)
inner join tprd tp on (tp.idprd = di.idprd)
inner join dtrbitem dti on (dti.idlaf = di.idlaf and dti.numitem = di.numitem)
where tp.descricao like '%arroz%' and dl.tipolf = 'S'
and dl.dataemissao >= '2011/07/01' and dl.dataemissao <= '2011/07/31'
and dti.sittributaria in ('04','06')
and dl.seriedoc in ('1','ECF') and dic.natrec is null
Se alguém puder ajudar fico grato
Link to comment
Share on other sites
1 answer to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.