Ver Mensaje Individual
  #1  
Antiguo 12-12-2005
uper uper is offline
Miembro
 
Registrado: abr 2004
Posts: 296
Reputación: 21
uper Va por buen camino
como actulizar un tabla desde un store procedure como un ciclo..

hola club

debo realizar una actualizacion entre tablas y he elegido usar store procedure con interbase6, la cuestion es que ya tengo el script pero no me hace lo que le digo:

Código PHP:
tengo una tabla fact_detalle con estos campos
FDET_ID
FDET_ELEMENTOFDET_CANTIDADFDET_PRECIOFDET_PEDIDO
y una tabla de Pedidos
DET_IND
DET_ORDENDET_CANTIDADDET_RESTANTE 
el Sp lo q- hace es lo siguiente, hace un select de Fact_detalle, guarda los campos fdet_pedido, fdet, cantidad, fdet_elemento, luego busca en el pedido DET_ORDEN, y el detalle det_id, y hace una resta para saber si es >0 sobra unidades y si es <0 falta unidades o bien si esta igual esta completo las unidades. (DET_CANTIDAD).

Código:
este es el store procedure
select count(*) from Fact_detalle where fdet_tipo='PED' and fdet_Id=: FDETALLE INTO :Contar;
if (:Contar>0) then
  FOR select fdet_pedido, fdet_elemento, fdet_cantidad from Fact_detalle
   where fdet_tipo='PED' and fdet_Id=:FDETALLE INTO :F_PEDIDO, :F_ELEM, :F_CANTIDAD do

   select DET_CANTIDAD from pedidos_detalle where DET_STATUS='E' and DET_IND=:F_PEDIDO AND DET_ORDEN=:F_ELEM
   into :deta_cantidad;
    R=F_CANTIDAD-deta_cantidad;

    if (R=0) then                /* completo */
      Update pedidos_detalle set DET_RESTANTE=0 where DET_IND=:F_PEDIDO AND DET_ORDEN=:F_ELEM;
     else
     if (R>0) then  /*  hay demas uniddes
       Update pedidos_detalle set DET_RESTANTE=0 where DET_IND=:F_PEDIDO AND DET_ORDEN=:F_ELEM;
     else
      if (R<0) then /*faltan unidades
        Total=R*(-R);   /* para que no sea un valor negativo
        
      Update pedidos_detalle set DET_RESTANTE=:Total where DET_IND=:F_PEDIDO AND DET_ORDEN=:F_ELEM;
de lo que se trata es de que en la tabla de pedidos me actulize el campo restante con este dato se conoce si aun faltan unidades para hacer mas partidas
me hace falta algo.
gracias.
Responder Con Cita