inicio
pChaveDinamica=3791698178819
pChaveAtual_1=29
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
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,
                    CUP           j,
                    CUP           k -- Ricardo 02/10/2020
               where a.pOrdem = b.pPId
                 and  b.pRepCom = j.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.lCrtlItem = 1
                 and  b.lGerarPreNF=0
                 and  b.lTransfRem=0
                 and  b.lTransfDep3o = 0
                 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  j.iVer = j.iVAt
                 and  e.jTipo= 0
                 and  a.lCrtlItem = 1
                 and  b.lGerarPreNF=0
                 and  b.jTipo= 1
                 and  b.jFase=2

                 and b.pDest = k.pPId and k.iVer = k.iVAt -- Ricardo 02/10/2020
                  
                 and cast(b.tEntPla as date) <= '01-Sep-2023'
and cast(b.tEntPlaCalc as date) <= '01-Sep-2023'
   -- dspaipar isso
                    -- dspaipar isso
                    -- dspaipar isso
                 
                  and a.pItem in (19495,19491,19492,19493,19691,21217,21218,60708,60709,63273,63274,0,63275,19494,19496,19633,19863,20060,19298,74804)
              order by b.pPId+0 -- Ricardo 03/05/2019
iCount_Db=0