[firebase-br] Problema com Procedure

Haroldo Dias haroldo em delfa.com.br
Sex Mar 27 10:38:59 -03 2009


Bom, coloquei uma condição após o DO (IF (:PRODUTO_CODIGO > 0) THEN) e 
funcionou legal, não entendo porque há necessidade dessa condição , já que 
todos os registros tem essa condição como verdadeira.


CREATE PROCEDURE SPU_NFE_OC (
    controle_1 integer)
returns (
    produto_codigo integer,
    oc_item_controle integer,
    iquantidade numeric(10,5),
    it01 numeric(10,5),    it02 numeric(10,5),    it03 numeric(10,5), 
it04 numeric(10,5),
    it05 numeric(10,5),    it06 numeric(10,5),    it07 numeric(10,5), 
it08 numeric(10,5),
    it09 numeric(10,5),    it10 numeric(10,5),    it11 numeric(10,5), 
it12 numeric(10,5),
    it13 numeric(10,5),    it14 numeric(10,5),    it15 numeric(10,5), 
it16 numeric(10,5),
    it17 numeric(10,5),    it18 numeric(10,5),    it19 numeric(10,5), 
it20 numeric(10,5),
    squantidade numeric(10,5),
    st01 numeric(10,5),    st02 numeric(10,5),    st03 numeric(10,5), 
st04 numeric(10,5),
    st05 numeric(10,5),    st06 numeric(10,5),    st07 numeric(10,5), 
st08 numeric(10,5),
    st09 numeric(10,5),    st10 numeric(10,5),    st11 numeric(10,5), 
st12 numeric(10,5),
    st13 numeric(10,5),    st14 numeric(10,5),    st15 numeric(10,5), 
st16 numeric(10,5),
    st17 numeric(10,5),    st18 numeric(10,5),    st19 numeric(10,5), 
st20 numeric(10,5),
    Rquantidade numeric(10,5),
    Rt01 numeric(10,5),    Rt02 numeric(10,5),    Rt03 numeric(10,5), 
Rt04 numeric(10,5),
    Rt05 numeric(10,5),    Rt06 numeric(10,5),    Rt07 numeric(10,5), 
Rt08 numeric(10,5),
    Rt09 numeric(10,5),    Rt10 numeric(10,5),    Rt11 numeric(10,5), 
Rt12 numeric(10,5),
    Rt13 numeric(10,5),    Rt14 numeric(10,5),    Rt15 numeric(10,5), 
Rt16 numeric(10,5),
    Rt17 numeric(10,5),    Rt18 numeric(10,5),    Rt19 numeric(10,5), 
Rt20 numeric(10,5))
as
BEGIN
for Select A.PRODUTO_CODIGO, A.OC_ITEM_CONTROLE, A.QUANTIDADE,
A.T01,A.T02,A.T03,A.T04,A.T05,A.T06,A.T07,A.T08,A.T09,A.T10,
A.T11,A.T12,A.T13,A.T14,A.T15,A.T16,A.T17,A.T18,A.T19,A.T20,
B.QUANTIDADE,
B.T01,B.T02,B.T03,B.T04,B.T05,B.T06,B.T07,B.T08,B.T09,B.T10,
B.T11,B.T12,B.T13,B.T14,B.T15,B.T16,B.T17,B.T18,B.T19,B.T20,
B.QUANTIDADE-A.QUANTIDADE,
B.T01-A.T01, B.T02-A.T02, B.T03-A.T03, B.T04-A.T04, B.T05-A.T05, 
B.T06-A.T06,
B.T07-A.T07, B.T08-A.T08, B.T09-A.T09, B.T10-A.T10, B.T11-A.T11, 
B.T12-A.T12,
B.T13-A.T13, B.T14-A.T14, B.T15-A.T15, B.T16-A.T16, B.T17-A.T17, 
B.T18-A.T18,
B.T19-A.T19, B.T20-A.T20
>From TbNfE_Item A, TbOc_Item_Saldo B
Where A.Oc_item_controle = B.Oc_item_controle
  AND A.NfE_Controle = :CONTROLE_1
  AND A.Oc > 0
Order By A.Oc_item_controle
INTO
:PRODUTO_CODIGO, :OC_ITEM_CONTROLE,:iQUANTIDADE,
:iT01,:iT02,:iT03,:iT04,:iT05,:iT06,:iT07,:iT08,:iT09,:iT10,
:iT11,:iT12,:iT13,:iT14,:iT15,:iT16,:iT17,:iT18,:iT19,:iT20,
:SQUANTIDADE,
:ST01,:ST02,:ST03,:ST04,:ST05,:ST06,:ST07,:ST08,:ST09,:ST10,
:ST11,:ST12,:ST13,:ST14,:ST15,:ST16,:ST17,:ST18,:ST19,:ST20,
:RQUANTIDADE,
:RT01,:RT02,:RT03,:RT04,:RT05,:RT06,:RT07,:RT08,:RT09,:RT10,
:RT11,:RT12,:RT13,:RT14,:RT15,:RT16,:RT17,:RT18,:RT19,:RT20
DO

IF (:PRODUTO_CODIGO > 0) THEN
   BEGIN

       Update TbOC_Item_Saldo Set
       Quantidade = Quantidade - :iQUANTIDADE,
       T01 = T01 - :iT01,   T02 = T02 - :iT02,   T03 = T03 - :iT03,
       T04 = T04 - :iT04,   T05 = T05 - :iT05,   T06 = T06 - :iT06,
       T07 = T07 - :iT07,   T08 = T08 - :iT08,   T09 = T09 - :iT09,
       T10 = T10 - :iT10,   T11 = T11 - :iT11,   T12 = T12 - :iT12,
       T13 = T13 - :iT13,   T14 = T14 - :iT14,   T15 = T15 - :iT15,
       T16 = T16 - :iT16,   T17 = T17 - :iT17,   T18 = T18 - :iT18,
       T19 = T19 - :iT19,   T20 = T20 - :iT20
       Where OC_Item_Controle = :OC_ITEM_CONTROLE;

   IF ((:RQUANTIDADE <= 0) AND
      (:RT01 <= 0) AND (:RT02 <= 0) AND (:RT03 <= 0) AND (:RT04 <= 0) AND
      (:RT05 <= 0) AND (:RT06 <= 0) AND (:RT07 <= 0) AND (:RT08 <= 0) AND
      (:RT09 <= 0) AND (:RT10 <= 0) AND (:RT11 <= 0) AND (:RT12 <= 0) AND
      (:RT13 <= 0) AND (:RT14 <= 0) AND (:RT15 <= 0) AND (:RT16 <= 0) AND
      (:RT17 <= 0) AND (:RT18 <= 0) AND (:RT19 <= 0) AND (:RT20 <= 0)) THEN
       BEGIN
       Update TbOc_Item Set
       Situacao = 2
       Where Controle = :OC_ITEM_CONTROLE;
       END

   END

END 







Mais detalhes sobre a lista de discussão lista