Ver Mensaje Individual
  #6  
Antiguo 26-08-2004
oliverinf oliverinf is offline
Miembro
 
Registrado: feb 2004
Posts: 65
Reputación: 21
oliverinf Va por buen camino
Con el siguiente procedimiento almacenado logre hacer lo que quería

CREATE PROCEDURE GET_ARBOLRUBROS (
ID_R INTEGER,
NIVEL INTEGER)
RETURNS (
NOMBRE VARCHAR (200))
AS
declare variable Id_Rub Integer;
declare variable CantHijos Integer;
declare variable i Integer;
declare variable NivelNuevo Integer;
declare variable Espacios VarChar(200);
BEGIN
/* Para todos los rubros hijos de Id_R. */
for select "Id_Rubro", "Nombre" from "Rubros"
where ("Id_Padre" = :Id_R)
order by "Nombre"
into :Id_Rub, :Nombre
do begin
/* Agrego tanto espacios en blanco como indica Nivel. */
Espacios = '';
i = 1;
while (i <= Nivel) do begin
Espacios = Espacios || ' ';
i = i + 1;
end

if (not (Espacios is null)) then
begin
/* Retorno los espacios concatenados con el nombre del rubro. */
Nombre = Espacios || Nombre;
end

/* Con este suspend retorno el Nombre del rubro padre. */
suspend;
/* Obtengo la cantidad de hijos del rubro padre. */
select count(*) from "Rubros"
where ("Id_Padre" = :Id_Rub)
into :CantHijos;

/* Si tiene hijos, volver a llamar al procedimiento. */
if (:CantHijos > 0) then
begin
NivelNuevo = Nivel + 1;
for select Nombre from get_arbolrubros(:Id_Rub, :NivelNuevo)
into :Nombre
do begin
/* Con este suspend retorno el Nombre del rubro hijo. */
suspend;
end
end
end

END
Responder Con Cita