dbo.obtener_garantias_brief_test

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_garantias_brief_test
@p_Cuit varchar(20)
AS
BEGIN
    SET NOCOUNT ON;
 declare @periodo_maximo date,@periodo_maximo_cuit date,@fecha_formateada varchar(10),@periodo_comparar varchar(6),@total int

 select @periodo_maximo = '2017-01-01'--(select max(fecha_informacion) from fuentes_procesadas where visible = '1' and fuente ='cendeu')

 select @periodo_maximo_cuit = convert(date,isnull(max(cendeu.fec_inf),'200112')+'01') from cendeu where iden = @p_cuit AND vigente = 1

 if (@periodo_maximo_cuit > @periodo_maximo) 
  begin 
     set @periodo_maximo = @periodo_maximo_cuit
  end 
 if @periodo_maximo is not null
  begin
  set @fecha_formateada = right('0' + rtrim(convert(varchar(6),(datepart(MM,@periodo_maximo)))),2) +'/'+convert(varchar(6),DATEPART(YY,@periodo_maximo))
  set @periodo_comparar =  convert(varchar(6),DATEPART(YY,@periodo_maximo))+  right('0' + rtrim(convert(varchar(6),(datepart(MM,@periodo_maximo)))),2)

  set @total = (select cast(sum(cgarprefa+cgarprefb+singarpref+deuda_total) as int) as total FROM cendeu_temp where iden=@p_Cuit and fec_inf =@periodo_comparar)
  if(@total is not null)
   begin
    select cast(sum(cgarprefa) as int) as cgarprefa,cast(sum(cgarprefb) as int ) as cgarprefb, 
    cast(sum(singarpref) as int) as singarpref,@total as total ,@fecha_formateada as ultimo_periodo FROM cendeu_temp where iden=@p_Cuit and fec_inf = @periodo_comparar
  
   end
  else
   begin
    select cast(sum(cgarprefa) as int) as cgarprefa,cast(sum(cgarprefb) as int ) as cgarprefb, 
    cast(sum(singarpref) as int) as singarpref,cast(sum(cgarprefa+cgarprefb+singarpref+deuda_total) as int) as total ,@fecha_formateada as ultimo_periodo FROM cendeu where iden=@p_Cuit and fec_inf = '201612'
   end
  end
  
END

GO

Used By

No items found