Ver Mensaje Individual
  #5  
Antiguo 24-02-2011
Avatar de gluglu
[gluglu] gluglu is offline
Miembro Premium
 
Registrado: sep 2004
Ubicación: Málaga - España
Posts: 1.455
Reputación: 21
gluglu Va por buen camino
Voy a cambiar la tabla de nombre para simplicarlo todo. Introducimos un único registro con un único valor = 1. Creamos el Stored Procedure.

Código Delphi [-]
CREATE TABLE PRUEBA(
    RANDOMNO DECIMAL(12,0)
);
 
INSERT INTO PRUEBA (RANDOMNO)
            VALUES (1);
COMMIT WORK;
 
SET TERM ^ ;
CREATE OR ALTER PROCEDURE NEW_PROCEDURE2 (
    in_random decimal(12,0))
returns (
    out_random decimal(12,0))
as
 declare variable aux_rand decimal(12,0);
 declare variable aux_rand2 decimal(12,0);
 declare variable aux_true integer;
begin
 
  AUX_TRUE  = 0;
 
  while (:"AUX_TRUE" = 0) do begin

    Select RANDOMNO from PRUEBA
      where RANDOMNO = :"IN_RANDOM"
      rows 1 into AUX_RAND;

    if (:"AUX_RAND" is null) then begin
      Leave;
    end
    else begin
      IN_RANDOM = IN_RANDOM + 1;
      if (IN_RANDOM > 200) then Leave;
    end

  end
 
  OUT_RANDOM = IN_RANDOM;
 
  suspend;
 
end
^
SET TERM ; ^

Y por último ejecutamos :
Código Delphi [-]
Select * from NEW_PROCEDURE2(1)
Esta sentencia me devuelve el valor 201.

Esta otra
Código Delphi [-]
Select * from NEW_PROCEDURE2(2)
me devuelve el valor 2.

Si pruebo con lo siguiente :
Código Delphi [-]
SET TERM ^ ;
CREATE OR ALTER PROCEDURE NEW_PROCEDURE2 (
    in_random decimal(12,0))
returns (
    out_random decimal(12,0))
as
 declare variable aux_rand decimal(12,0);
 declare variable aux_rand2 decimal(12,0);
 declare variable aux_true integer;
begin
 
  AUX_TRUE  = 0;
 
  while (:"AUX_TRUE" = 0) do begin

    Select RANDOMNO from PRUEBA
      where RANDOMNO = :"IN_RANDOM"
      rows 1 into AUX_RAND;

    if (:"AUX_RAND" is null) then begin
      Leave;
    end
    else begin
      IN_RANDOM = IN_RANDOM + 1;
      if (IN_RANDOM > 200) then Leave;
    end

  end
 
  OUT_RANDOM = AUX_RAND;
 
  suspend;
 
end
^
SET TERM ; ^
para ver qué valor queda en Aux_Rand, entonces

Código Delphi [-]
Select * from NEW_PROCEDURE2(1)
me devuelve el valor 1
y
Código Delphi [-]
Select * from NEW_PROCEDURE2(2)
me devuelve null.

P.D. La versión de Firebird es la 2.1
__________________
Piensa siempre en positivo !
Responder Con Cita