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 | 20 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
CREATE OR ALTER PROCEDURE dbo.obtener_card_bancos_test2
@p_Cuit varchar(20)
AS
BEGIN
SET NOCOUNT ON;
declare @p_5anios date = getdate() - (5*365)
declare @p_2anios date = getdate() - (2*365)
declare @p_3meses date = getdate() - (90)
declare @periodo_maximo date,
@periodo_maximo_cuit varchar(7),
@periodo_maximo_cuit_temp varchar(7),
@fecha_formateada varchar(10),
@periodo_comparar varchar(6);
--select @periodo_maximo = (select max(fecha_informacion) from fuentes_procesadas where visible = '1')
select @periodo_maximo_cuit = max(cendeu.fec_inf) from cendeu where iden = @p_cuit AND vigente = 1
select @periodo_maximo_cuit_temp = max(cendeu_temp.fec_inf) from cendeu_temp where iden = @p_cuit AND vigente = 1
if(@periodo_maximo_cuit_temp > @periodo_maximo_cuit)
begin
set @periodo_maximo_cuit = @periodo_maximo_cuit_temp
end
set @periodo_maximo = convert(date,@periodo_maximo_cuit+'01')
set @periodo_comparar = @periodo_maximo_cuit
if (@periodo_maximo is not null )
begin
select distinct count(*) as cantidad_bancos,
@periodo_maximo as periodo,
sum((prestamos+particip+garotor+o_cptos+deuda_total)) as deuda_total
from cendeu where iden = @p_Cuit and fec_inf = @periodo_comparar and vigente = 1
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 = 1 and b.id_fuente = 2 and b.id_cendeu != cendeu.id_cendeu)
and not (
(cast(fec_inf+'01' as date) < @p_5anios)
OR
(cast(fec_inf+'01' as date) < @p_2anios
and
--not (convert(date,created) > @p_3meses and convert(date,modified) > @p_3meses))
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 (convert(date,c.created) > @p_3meses)))
OR
(cast(fec_inf+'01' as date) < @p_2anios
and
exists (select * from cendeu_cancela c
where c.iden = cendeu.iden
and cast(c.codigo_ent as int) = cast(cendeu.codigo_ent as int)
and cast(fec_inf+'01' as date) between convert(date,c.fec_inf_desde) and convert(date,c.fec_inf_hasta)
and c.vigente = '1'))
)
having count(*) > 0
union all
select distinct count(*) as cantidad_bancos,@periodo_maximo as periodo,sum((prestamos+particip+garotor+o_cptos+deuda_total)) as deuda_total from cendeu_temp where iden = @p_Cuit and fec_inf = @periodo_comparar and vigente = 1
and not exists (select * from cendeu_temp b where b.iden = cendeu_temp.iden and cast(b.codigo_ent as int) = cast(cendeu_temp.codigo_ent as int) and b.fec_inf = cendeu_temp.fec_inf and b.vigente = 1 and b.id_fuente = 2 and b.id_cendeu != cendeu_temp.id_cendeu)
and not (
(cast(fec_inf+'01' as date) < @p_5anios)
OR
(cast(fec_inf+'01' as date) < @p_2anios
and
--not (convert(date,created) > @p_3meses and convert(date,modified) > @p_3meses))
not exists (select * from cendeu_temp c where c.iden = cendeu_temp.iden and cast(c.codigo_ent as int) = cast(cendeu_temp.codigo_ent as int) and (convert(date,c.created) > @p_3meses)))
OR
(cast(fec_inf+'01' as date) < @p_2anios
and
exists (select * from cendeu_cancela c
where c.iden = cendeu_temp.iden
and cast(c.codigo_ent as int) = cast(cendeu_temp.codigo_ent as int)
and cast(fec_inf+'01' as date) between convert(date,c.fec_inf_desde) and convert(date,c.fec_inf_hasta)
and c.vigente = '1'))
)
having count(*) > 0
end
END
GO
GO
CREATE OR ALTER PROCEDURE dbo.obtener_card_bancos_test2
@p_Cuit varchar(20)
AS
BEGIN
SET NOCOUNT ON;
declare @p_5anios date = getdate() - (5*365)
declare @p_2anios date = getdate() - (2*365)
declare @p_3meses date = getdate() - (90)
declare @periodo_maximo date,
@periodo_maximo_cuit varchar(7),
@periodo_maximo_cuit_temp varchar(7),
@fecha_formateada varchar(10),
@periodo_comparar varchar(6);
--select @periodo_maximo = (select max(fecha_informacion) from fuentes_procesadas where visible = '1')
select @periodo_maximo_cuit = max(cendeu.fec_inf) from cendeu where iden = @p_cuit AND vigente = 1
select @periodo_maximo_cuit_temp = max(cendeu_temp.fec_inf) from cendeu_temp where iden = @p_cuit AND vigente = 1
if(@periodo_maximo_cuit_temp > @periodo_maximo_cuit)
begin
set @periodo_maximo_cuit = @periodo_maximo_cuit_temp
end
set @periodo_maximo = convert(date,@periodo_maximo_cuit+'01')
set @periodo_comparar = @periodo_maximo_cuit
if (@periodo_maximo is not null )
begin
select distinct count(*) as cantidad_bancos,
@periodo_maximo as periodo,
sum((prestamos+particip+garotor+o_cptos+deuda_total)) as deuda_total
from cendeu where iden = @p_Cuit and fec_inf = @periodo_comparar and vigente = 1
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 = 1 and b.id_fuente = 2 and b.id_cendeu != cendeu.id_cendeu)
and not (
(cast(fec_inf+'01' as date) < @p_5anios)
OR
(cast(fec_inf+'01' as date) < @p_2anios
and
--not (convert(date,created) > @p_3meses and convert(date,modified) > @p_3meses))
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 (convert(date,c.created) > @p_3meses)))
OR
(cast(fec_inf+'01' as date) < @p_2anios
and
exists (select * from cendeu_cancela c
where c.iden = cendeu.iden
and cast(c.codigo_ent as int) = cast(cendeu.codigo_ent as int)
and cast(fec_inf+'01' as date) between convert(date,c.fec_inf_desde) and convert(date,c.fec_inf_hasta)
and c.vigente = '1'))
)
having count(*) > 0
union all
select distinct count(*) as cantidad_bancos,@periodo_maximo as periodo,sum((prestamos+particip+garotor+o_cptos+deuda_total)) as deuda_total from cendeu_temp where iden = @p_Cuit and fec_inf = @periodo_comparar and vigente = 1
and not exists (select * from cendeu_temp b where b.iden = cendeu_temp.iden and cast(b.codigo_ent as int) = cast(cendeu_temp.codigo_ent as int) and b.fec_inf = cendeu_temp.fec_inf and b.vigente = 1 and b.id_fuente = 2 and b.id_cendeu != cendeu_temp.id_cendeu)
and not (
(cast(fec_inf+'01' as date) < @p_5anios)
OR
(cast(fec_inf+'01' as date) < @p_2anios
and
--not (convert(date,created) > @p_3meses and convert(date,modified) > @p_3meses))
not exists (select * from cendeu_temp c where c.iden = cendeu_temp.iden and cast(c.codigo_ent as int) = cast(cendeu_temp.codigo_ent as int) and (convert(date,c.created) > @p_3meses)))
OR
(cast(fec_inf+'01' as date) < @p_2anios
and
exists (select * from cendeu_cancela c
where c.iden = cendeu_temp.iden
and cast(c.codigo_ent as int) = cast(cendeu_temp.codigo_ent as int)
and cast(fec_inf+'01' as date) between convert(date,c.fec_inf_desde) and convert(date,c.fec_inf_hasta)
and c.vigente = '1'))
)
having count(*) > 0
end
END
GO
Depends On
3Used By
No items found