Jump to content
Fórum Script Brasil
  • 0

update + join


ROMANVPP

Question

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

  • 0

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 null

Caso de algum erro, escreve aqui pra gente.

NIK

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...