inicio
pChaveDinamica=3791628189981
Query das conversoes de unidades de medidas - select pItem,pUni1,pUni2,nFator,pPId,iVAt from Conversao_UnidadeMedida where iVer=iVAt and lExc=0 order by pItem desc
Query da oferta dos depsitos - select a.pItem,
                      c.pPId,
                      (c.nSdo-c.nRes)+coalesce(i.nSdo-i.nRes,0),
                      c.pUni,
                      d.jDec,
                      e.sCodigo,
                      c.iVer,
                      c.nSdo,
                      c.nRes,
                      (c.nSdo-c.nRes)+coalesce(i.nSdo-i.nRes,0)  -- esse campo repete porq preciso ter o valor original do saldo
               from Ordens_Itens     a      join Ordens           b on a.pOrdem     = b.pPId    and b.iVer = b.iVAt    and b.lExc = 0       and b.jTipo = 1 and case when (b.tConf is null) then 0 else 1 end = 1 --and b.tConf is not null -- Ricardo 03/05/2019
                                            join EST_RegDepositos c on a.pRegDepVen = c.pPId    and c.iVer = c.iVAt    and c.lExc = 0       and (c.nSdo - c.nRes)>=0
                                            join UnidadeMedida    d on c.pUni       = d.pPId    and d.iVer = d.iVAt
                                            join Itens            e on a.pItem+0      = e.pPId    and e.iVer = e.iVAt    and e.lExc = 0       and e.jTipo = 0 -- Ricardo 14/01/2019
                                       left join GrUNeg_Linha     f on e.pUNeg      = f.pUNeg   and f.iVer = f.iVAt    and f.lExc = 0
                                       left join GrUNeg_Capa      g on f.pCapa      = g.pPId    and g.iVer = g.iVAt    and g.lExc = 0
                                       left join Itens            h on e.sCodigo    = h.sCodigo and g.pUNeg = h.pUNeg  and h.iVer = h.iVAt  and h.lExc = 0
                                       left join EST_RegDepositos i on h.pPId       = i.pItem   and g.pDep  = i.pDep   and g.pIns = i.pIns  and i.iVer = i.iVAt and i.lExc = 0
               where  a.lExc = 0
                 and  a.iVer = a.iVAt
                 and (a.nQt - a.nQtRes-a.nQtBO-a.nQtCanc) > 0
                  and b.pPId=709059    -- dspaipar isso
               group by a.pItem,c.pPId,c.pUni,d.jDec,e.sCodigo,c.iVer,c.nSdo,c.nRes,i.nSdo,i.nRes
               order by 1,2
iCount_RegDep=0
Query das demandas das Ordens - select b.pTOper,a.pItem,(a.nQt-a.nQtRes-a.nQtBO-a.nQtCanc),a.nQtRes,a.pPId,a.pOrdem,a.pUni,c.jDec,a.iVer,a.nQt,a.pRegDepVen,a.pLote,a.iSerial,b.lGlobal,pNA_Bonif,lNA_Bonif,lLimCred
               from Ordens_Itens  a,
                    Ordens        b,
                    UnidadeMedida c,
                    Itens         e
               where a.pOrdem = b.pPId
                 --and  b.tConf is not null                            -- Ricardo 03/05/2019
                 and case when (b.tConf is null) then 0 else 1 end = 1 -- Ricardo 03/05/2019
                 and  a.pUni  = c.pPId  
                 and  a.pItem = e.pPId
                 and (a.nQt-a.nQtRes-a.nQtBO-a.nQtCanc) > 0
                 and  a.lExc = 0
                 and  b.lExc = 0
                 and  a.iVer = a.iVAt
                 and  b.iVer = b.iVAt
                 and  c.iVer = c.iVAt
                 and  e.iVer = e.iVAt
                 and  e.jTipo= 0
                 and  a.lCrtlItem = 1
                 and  b.lGerarPreNF=0
                 and  b.jTipo= 1
                  and b.pPId=709059 
              order by b.pPId+0 -- Ricardo 03/05/2019
iCount_Db=0