inicio
pChaveAtual_1=11, psPesquisarFull=
sWhr=
sSql=
              select a.pIt2,
                     c.sCodigo,
                     c.sDescricao,
                     h.sCodigo sUni,
                     cast(g.tPrevDe as date)   dDt1,
                     cast(g.tPrevDe as date)+1 dDt2,
                     cast(g.tPrevDe as date)+2 dDt2,
                     cast(g.tPrevDe as date)+3 dDt3,
                     sum(case when cast(b.tPrevIni as date)  = cast(g.tPrevDe as date)   then a.nPrevisao else 0 end) nVal1,
                     sum(case when cast(b.tPrevIni as date)  = cast(g.tPrevDe as date)+1 then a.nPrevisao else 0 end) nVal2,
                     sum(case when cast(b.tPrevIni as date)  = cast(g.tPrevDe as date)+2 then a.nPrevisao else 0 end) nVal3,
                     sum(case when cast(b.tPrevIni as date) >= cast(g.tPrevDe as date)+3 then a.nPrevisao else 0 end) nVal4,
                     sum(a.nPrevisao) nTotal,
                     0,   -- 13
                     sum(cast(a.nPrevisao as numeric(18,5)))   -- 14
              from   OPCapa_Bom                 a,
                     OPCapa                     b,
                     Itens                      c,
                     EST_RegDepositos           d,
                     BOM                        e,
                     OP_Rel_Insumos01_Depositos f,
                     OP_Rel_Insumos01           g,
                     UnidadeMedida              h
              where  a.pOpCapa   = b.pPId
                and  a.pIt2+0    = d.pItem+0 -- Ricardo 15/03/2019
                --and  b.tConf is not null                              -- Ricardo 22/03/2019
                and (case when (b.tConf is null) then 0 else 1 end) = 1 -- Ricardo 22/03/2019
                and  b.tConc+0 is     null                              -- Ricardo 22/03/2019
                and  f.pCapa+0   = g.pPId -- Ricardo 15/03/2019
                and  g.pPId    = 11
                and  d.pDep+0    = f.pDep+0 -- Ricardo 15/03/2019
                and  d.pIns+0    = f.pIns+0 -- Ricardo 15/03/2019
                and  b.pItem+0   = e.pIt1+0 -- Ricardo 15/03/2019
                and  d.pItem+0   = e.pIt2+0 -- Ricardo 15/03/2019
                and  a.pIt2    = c.pPId
                and  a.pUni    = h.pPId
                and  b.tPrevIni >= g.tPrevDe
                and  b.tPrevIni <= g.tPrevAte
                and  b.pUNeg+0 = g.pEmi -- Ricardo 15/03/2019
                and  a.pRegDep = d.pPId
                and  a.lBaixarBOM=1
    
                and  a.iVer = a.iVAt and  a.lExc=0
                and  b.iVer = b.iVAt and  b.lExc=0
                and  c.iVer = c.iVAt and  c.lExc=0
                and  d.iVer = d.iVAt and  d.lExc=0
                and  e.iVer = e.iVAt and  e.lExc=0
                and  f.iVer = f.iVAt and  f.lExc=0
                and  g.iVer = g.iVAt
                and  h.iVer = h.iVAt

                
                      
              group by a.pIt2,
                       c.sCodigo,
                       c.sDescricao,
                       h.sCodigo,
                       cast(g.tPrevDe as date)
              order by cast(g.tPrevDe as date)
             
iDb1=0
sInItens=0
sSql=select d.pItem,sum(d.nSdo-d.nRes)
              from EST_RegDepositos           d,
                   OP_Rel_Insumos01_Depositos f,
                   OP_Rel_Insumos01           g
              where f.pCapa+0   = g.pPId+0            -- Ricardo 18/09/2018
                and g.pPId+0    = 11      -- Ricardo 18/09/2018
                and d.pDep+0    = f.pDep+0            -- Ricardo 18/09/2018
                and d.pIns+0    = f.pIns+0            -- Ricardo 18/09/2018
                and d.pItem in (0)
                and d.iVer = d.iVAt
                and f.iVer = f.iVAt
                and g.iVer = g.iVAt
                and d.lExc=0
                and f.lExc=0
              group by d.pItem
             
iDb2=0
k=0
sRet=