Stored Procedure executed within another with two outputs to be assigned to a variable

0

Dear, I am running an SP in Sybase that executes another SP according to certain conditions, this SP will have two output values but only one of them will be output in each execution, my problem is that one of the two values will be print without problems the other does not do it

Let's look at the codes, stored procedure parent (I only place the operation where I'm calling)

if @i_operacion = "R" 

select @w_ente = @i_cliente

begin
    -- BUSCAR LA CANTIDAD DE NUMEROS O PREGUNTAS QUE SE OBTENDRAN DE ACUERDO AL MOTIVO

    SELECT @w_tot_preg = mv_preg_totales
    FROM cc_motivo_validacion
    WHERE mv_codigo = @i_motivo

    CREATE TABLE #TempNum(
        numero int null,
        descripcion varchar(200) null,
        respuesta varchar(250) null,
        codigo int null
        )

    if @i_tipo = "P"
    begin
        select @w_tipo_ente = 'PN'
    end

    if @i_tipo = "C"
    begin
        select @w_tipo_ente = 'PJ'
    end

-- BUSCAR LA CANTIDAD DE PREGUNTAS EXISTENTES PARA CONOCER EL RANGO DEL ALEATORIO   

        SELECT @w_cant_preg = COUNT (*) 
        from cc_preguntas_validacion 
        WHERE pv_tipo = @w_tipo_ente or pv_tipo = "PG"

        select @w_inf = 1
        select @w_sup = @w_cant_preg
        select @w_p_cicl = 1

        WHILE (@w_p_cicl < @w_tot_preg+1)
        begin
            SELECT @w_num_rand = ROUND(((@w_sup -  @w_inf -1) * rand() + @w_inf),0) 
            INSERT INTO #TempNum
                (numero)
            Values
                (@w_num_rand)   
            select @w_p_cicl = @w_p_cicl + 1
        end

    SELECT top 1 @w_comp = numero
    FROM #TempNum
    Order by numero ASC

    declare curpreguntas cursor
    for
    SELECT pv_codigo, pv_descripcion FROM
    cob_cuentas..cc_preguntas_validacion
    WHERE pv_tipo = @w_tipo_ente or pv_tipo = "PG"
    ORDER BY pv_codigo ASC

    select @w_temp = 1
    open curpreguntas
    fetch curpreguntas into
    @w_cod_preg,
    @w_pregunta

    while @@sqlstatus = 0
    begin

        if @w_temp=@w_comp

        begin

            exec sp_resp_validacion_positiva
                 @i_codigo = @w_cod_preg,
                 @i_cliente = @w_ente,
                 @o_resp_corta = @w_respuesta out,
                 @o_resp_larga = @w_respuesta out

                Select @w_respuesta

                Update #TempNum
                Set
                descripcion = @w_pregunta,
                codigo = @w_cod_preg,
                respuesta = @w_respuesta
                WHERE numero = @w_comp 

            set @w_respuesta = ""

            SELECT top 1 @w_comp = numero
                from
                #TempNum
                Where @w_comp < numero
                ORDER BY numero ASC

        end

        select @w_temp = @w_temp + 1
        fetch curpreguntas into
             @w_cod_preg,
             @w_pregunta
        end
    close curpreguntas
    deallocate curpreguntas

    SELECT 'NUMERO' = numero,
            'CODIGO' = codigo,
           'DESCRIPCION' = descripcion,
           'RESPUESTA' = respuesta
    FROM
           #TempNum


    DROP TABLE #TempNum

Stored procedure son

    create proc sp_resp_validacion_positiva (
            @s_ssn      int = null,
            @s_user     login = null,
            @s_term     varchar(30) = null,
            @s_date     datetime = null,
            @s_srv      varchar(30) = null,
            @s_lsrv     varchar(30) = null,
            @t_debug    char(1) = 'N',
            @t_file     varchar(14) = null,
            @t_from     varchar(32) = null,
            @t_trn      smallint = null,
            @i_codigo       int,
            @i_cliente      int = null,
            @o_resp_corta      char(1) = null out,
            @o_resp_larga   varchar(150) = null out           
) as
declare     @w_sp_name       varchar(30),
                @w_ente         int,
                @w_diaN         varchar(2),
                @w_mesN         varchar(3),
                @w_anoN         varchar(4),
                @w_ced_ruc      varchar(30),
                @w_tlf          varchar(4),
                @w_email            varchar(50),
                @w_cta          varchar(30),
                @w_detalle_dir  varchar(100),
                @w_direccion    varchar(105),
                @w_pais         varchar(100),
                @w_estado       varchar(100),
                @w_ciudad       varchar(100),
                @w_zip          varchar(10),
                @w_correo       varchar(100),
                @w_return        int


/*  Inicializa Variables  */
select  @w_sp_name = 'sp_resp_validacion_positiva',
        @o_resp_corta = 'N'

select  @w_ente = @i_cliente

select @w_ced_ruc = en_ced_ruc
from    cobis..cl_ente
where en_ente = @w_ente

SELECT TOP 1 @w_cta = cc_cta_banco
FROM cob_cuentas..cc_ctacte
WHERE cc_cliente = @w_ente

if @i_codigo = 1

    begin
        select  @w_anoN     =  substring(p_fecha_nac,8,4)
        from cobis..cl_ente
        where en_ced_ruc = @w_ced_ruc

        select @o_resp_larga =  CONVERT(VARCHAR(4), @w_anoN, 365)

        select @o_resp_larga
    end

if @i_codigo = 2

    begin
        select  @w_mesN = substring(convert(varchar(10), p_fecha_nac, 103),4,2)
            from cobis..cl_ente
        where en_ced_ruc = @w_ced_ruc

        select @o_resp_larga = CONVERT(VARCHAR(4), @w_mesN, 365)

        select @o_resp_larga
    end

if @i_codigo = 3

    begin
        select  @w_diaN = substring(p_fecha_nac,5,2)
        from cobis..cl_ente
        where en_ced_ruc = @w_ced_ruc

        select @o_resp_larga = CONVERT(VARCHAR(4), @w_diaN, 365)

        select @o_resp_larga
    end

if @i_codigo = 4
    begin

    IF EXISTS (select 1 from cob_atm..tm_tarj_cred
        where tc_ente = @w_ente
        and tc_virtual = 'N'
        and tc_estado = 'A'
        and tc_tipo_tarj = 'T')
        begin
        select @o_resp_corta = 'S'
        end
    SELECT @o_resp_corta

    end

if @i_codigo = 5

    begin
        IF EXISTS (select 1 from cob_atm..tm_tarj_cred t, cob_atm..tm_tarj_cred a
        where t.tc_ente = @w_ente
        and t.tc_virtual = 'N'
        and t.tc_estado = 'A'
        and t.tc_tipo_tarj = 'T'
        and t.tc_num_tarj = a.tc_tarj_principal
        and a.tc_virtual = 'N'
        and a.tc_estado = 'A'
        and a.tc_tipo_tarj = 'A')
        begin
                    select @o_resp_corta = 'S'
            end
            SELECT @o_resp_corta
    end

if @i_codigo = 6

    begin
        IF EXISTS (select 1 from cob_cuentas..cc_ctacte
        where cc_cliente = @w_ente)
            begin
                    select @o_resp_corta = 'S'
            end
            SELECT @o_resp_corta
    end

if @i_codigo = 7

    begin
        IF EXISTS (select 1 from cob_atm..tm_tarj_cred
        where 
        tc_estado = 'A'
        and tc_tarj_principal = STR(@w_ente))
                begin
                    select @o_resp_corta = 'S'
                end
            SELECT @o_resp_corta
    end

if @i_codigo = 8

    begin
        select top 1
                @w_detalle_dir  = di_descripcion,
                @w_pais         = (select pa_descripcion from cobis..cl_pais where pa_pais = cobis..cl_direccion.di_pais),
                @w_estado       = (select pv_descripcion from cobis..cl_provincia where pv_provincia = cobis..cl_direccion.di_estado),
                @w_ciudad       = (select distinct ci_descripcion from cobis..cl_ciudad where ci_provincia = cobis..cl_direccion.di_estado and ci_pais = cobis..cl_direccion.di_pais and ci_ciudad = cobis..cl_direccion.di_ciudad),
                @w_zip          = isnull(di_codpos, "0")
            from cobis..cl_direccion
            where di_ente = @w_ente 
            and di_tipo= 'D'        

            select @w_direccion = @w_pais
                if @w_zip <> "0"
                    select @w_direccion = @w_zip  + ', ' + @w_direccion 

                if @w_estado <> null and @w_estado <> "NO APLICA"
                    select @w_direccion = @w_estado  + ', ' + @w_direccion 

                if @w_ciudad <> null
                    select @w_direccion = @w_ciudad  + ', ' + @w_direccion 

                select @w_direccion = + ', ' + @w_direccion 
                select @w_direccion = substring(@w_detalle_dir, 1, (105 - datalength(@w_direccion))) + @w_direccion

            select @o_resp_larga = @w_direccion 

            SELECT @o_resp_larga
    end

if @i_codigo = 9

    begin
        select top 1
            @w_email = di_descripcion
            from cobis..cl_direccion
            where di_ente = @w_ente 
            and di_tipo= 'M'    

            select @o_resp_larga = @w_email

            SELECT @o_resp_larga
    end

if @i_codigo = 10

    begin
        select @w_tlf = substring(te_valor, LEN(te_valor)-3, 4)
               from cobis..cl_telefono, cobis..cl_catalogo
               where codigo = te_tipo_telefono
               and tabla = 26                                        
               and estado <> 'B'
               and valor = 'DOMICILIO'
               and te_ente = @w_ente

               select @o_resp_larga = @w_tlf

            SELECT @o_resp_larga
    end

if @i_codigo = 11

    begin
        SELECT @w_ced_ruc = en_ced_ruc
            from cobis..cl_ente
            WHERE en_ente = @w_ente

             select @o_resp_larga = @w_ced_ruc

            SELECT @o_resp_larga
    end

if @i_codigo = 12

    begin
        IF EXISTS(select 1 from cob_cartera..ca_operacion
                where op_estado in (1,2)
                and op_cliente = @w_ente)
                    begin
                        select @o_resp_corta = 'S'
                    end
            SELECT @o_resp_corta
    end

if @i_codigo = 13

    begin
        IF EXISTS(SELECT op_num_banco FROM cob_pfijo..pf_operacion 
                  WHERE op_ente = @w_ente)
                    begin
                        select @o_resp_corta = 'S'
                    end
            SELECT @o_resp_corta
    end

if @i_codigo = 14

    begin
        IF EXISTS(select * from cob_cuentas_his..cc_his_movimiento
        where hm_cta_banco = @w_cta
        and hm_tipo_tran = 50)
                begin
                    select @o_resp_corta = 'S'
                end
            SELECT @o_resp_corta
    end

if @i_codigo = 15

    begin
        IF EXISTS(select * from cob_cuentas_his..cc_his_movimiento
        where hm_cta_banco = @w_cta
        and hm_tipo_tran = 48)
                begin
                    select @o_resp_corta = 'S'
                end

            SELECT @o_resp_corta
    end

return 0
    
asked by Carlos Alberto Pedron 15.06.2018 в 15:30
source

0 answers