dbo.obtener_status_bancario_old1

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

1
Name Data Type Length Description
@p_cuit varchar 12

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO

CREATE OR ALTER PROCEDURE dbo.obtener_status_bancario_old1
@p_cuit varchar(12)
AS
BEGIN
    SET NOCOUNT ON;

 declare @cheques_rechazados int,@situaciones int,@ultima_posicion int,@max int,@fec_inf varchar(20)
            
 select @max = max(subquery.maximo) from (select fec_inf,sum((prestamos+particip+garotor+o_cptos+deuda_total)*1000) as maximo 
           from cendeu 
           where iden = @p_cuit
           and vigente =1 
           and convert(date,fec_inf+'01') > getdate() - 770 
           and not exists (select * from cendeu c 
                            where c.iden = cendeu.iden 
                  and cast(c.codigo_ent as int) = cast(cendeu.codigo_ent as int) 
                  and c.fec_inf = cendeu.fec_inf 
                  and c.vigente = 1 
                  and c.id_fuente = 2 
                  and c.id_cendeu != cendeu.id_cendeu)
           and not exists (select * from cendeu b 
                where b.iden = cendeu.iden
                and  cast(b.codigo_ent as int) = cast(cendeu.codigo_ent as int)
                and  b.fec_inf = cendeu.fec_inf
                and  b.vigente = cendeu.vigente
                and  b.id_cendeu < cendeu.id_cendeu)
           group by fec_inf ) subquery

          
     select @fec_inf = (select top 1 fec_inf
   from cendeu 
   where iden = @p_cuit 
   and vigente =1 
   and convert(date,fec_inf+'01') > getdate() - 770 
   and @max = (select max(subquery.maximo) from (select  fec_inf,sum(prestamos+particip+garotor+o_cptos+deuda_total) as maximo 
           from cendeu 
           where iden = @p_cuit  
           and vigente =1 
           and convert(date,fec_inf+'01') > getdate() - 770 
           and not exists (select * from cendeu c 
                            where c.iden = cendeu.iden 
                  and cast(c.codigo_ent as int) = cast(cendeu.codigo_ent as int) 
                  and c.fec_inf = cendeu.fec_inf 
                  and c.vigente = 1 
                  and c.id_fuente = 2 
                  and c.id_cendeu != cendeu.id_cendeu)
           and not exists (select * from cendeu b 
                where b.iden = cendeu.iden
                and  cast(b.codigo_ent as int) = cast(cendeu.codigo_ent as int)
                and  b.fec_inf = cendeu.fec_inf
                and  b.vigente = cendeu.vigente
                and  b.id_cendeu < cendeu.id_cendeu)
           group by fec_inf) subquery))
         


 --select @fec_inf = convert(varchar,convert(date,fec_inf+'01'),103)  from cendeu where iden = @p_cuit and cendeu.vigente = 1 and convert(date,fec_inf+'01') > getdate() - 770
 select @cheques_rechazados = count(*) from ChequesBCRA where cuit_firmante = @p_cuit AND fecha_rechazo > getdate() - 770 and visible = 1
 select @situaciones = count(situacion) from cendeu where iden = @p_cuit and situacion > 01 and vigente = 1 and convert(date,fec_inf+'01') > getdate() - 770
               and not exists (select * from cendeu b 
                where b.iden = cendeu.iden
                and  cast(b.codigo_ent as int) = cast(cendeu.codigo_ent as int)
                and  b.fec_inf = cendeu.fec_inf
                and  b.vigente = cendeu.vigente
                and  b.id_cendeu < cendeu.id_cendeu)
/*
select @ultima_posicion = isnull(sum(prestamos+particip+garotor+o_cptos+deuda_total),0)  from cendeu where iden = @p_cuit and cendeu.vigente = 1 and fec_inf = (select max(fec_inf) from cendeu where iden = @p_cuit and cendeu.vigente = 1)
*/

 select @ultima_posicion = isnull(sum((prestamos+particip+garotor+o_cptos+deuda_total)*1000),0)  
   from cendeu 
    where iden = @p_cuit 
    and cendeu.vigente = 1
    and fec_inf = (select max(fec_inf) from cendeu where iden = @p_cuit and cendeu.vigente = 1 and convert(date,fec_inf+'01') > getdate() - 770) 
    and not exists (select * from cendeu b 
        where b.iden = cendeu.iden
        and  cast(b.codigo_ent as int) = cast(cendeu.codigo_ent as int)
        and  b.fec_inf = cendeu.fec_inf
        and  b.vigente = cendeu.vigente
        and  b.id_cendeu < cendeu.id_cendeu)


 
 select top 1 @cheques_rechazados as cheques_rechazados,@situaciones as situaciones,@ultima_posicion as ultima_posicion, @max as maxima_posicion,@fec_inf as fec_inf

END

GO

Used By

No items found