dbo.buscar_empleadores_cursor

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
CREATE OR ALTER PROCEDURE dbo.buscar_empleadores_cursor

AS
/*
select distinct  cuit,fecha_nacimiento,sexo,ingreso_bruto,periodo_ingreso,cantidad_empleadores from enriquecimiento_bdd_pro order by cuit



select distinct enriquecimiento_bdd_pro.cuit,domicilios_todos.domicilio,domicilios_todos.loc_nombre,domicilios_todos.prv_nombre,
case
when tipo_domicilio = 'O' then 'Otros'
when tipo_domicilio = 'D' then 'Real'
when tipo_domicilio = 'L' then 'Legal'
when tipo_domicilio = 'F' then 'Fiscal'
end as tipo_domicilio
 from domicilios_todos
inner join enriquecimiento_bdd_pro on enriquecimiento_bdd_pro.cuit = domicilios_todos.cuit and visible = 1   
and tipo_domicilio not in('I','E')
order by enriquecimiento_bdd_pro.cuit

select distinct telefono,telefonos.id_padron,identificacion,null as telefono_formateado  into telefonos_pro_temp from telefonos
inner join padrones on padrones.id_padron = telefonos.id_padron
where telefonos.id_padron in (
select id_padron from enriquecimiento_bdd_pro inner join padrones on padrones.identificacion = enriquecimiento_bdd_pro.cuit and habilitado = 1)

update TABLE_A
set TABLE_A.telefono_formateado = '('+iif(len(ttt.TLD)<4,'0'+ttt.TLD,ttt.tld) +')'+PRF+'-'+SFJ
from telefonos_pro_temp as TABLE_A
inner join TE_tasa_temp ttt on ttt.TEL_N = telefono
WHERE
TABLE_A.telefono = TEL_N
 

 update TABLE_A
set TABLE_A.telefono_formateado = '('+tpt.prefijo+')'+'15'+tpt.LINEA_SIN_PREFIJO
from telefonos_pro_temp as TABLE_A
inner join te_personal_temp tpt on tpt.LINEA = telefono
WHERE
TABLE_A.telefono = LINEA

SELECT DISTINCT identificacion,telefono,telefono_formateado FROM telefonos_pro_temp
*/





BEGIN
    SET NOCOUNT ON;
declare @id_ebp int
declare @cuit_procesar varchar(20)
DECLARE ProdInfo CURSOR FOR

select distinct cuit,id_ebp  from  enriquecimiento_bdd_pro where sexo is not null
OPEN ProdInfo

FETCH NEXT FROM ProdInfo INTO @cuit_procesar,@id_ebp

WHILE @@fetch_status = 0

 BEGIN
 declare @cantidad_empleadores int
 declare @monto decimal(20,2)
  set @cantidad_empleadores = (select   COUNT (distinct(cuit)) from empleados where empleados.cuil = @cuit_procesar and periodo = '1712')
  if(@cantidad_empleadores = 1)
   begin
   set @monto = (select max(remtot) from empleados where empleados.cuil = @cuit_procesar and periodo = '1712')
  set @cantidad_empleadores = 1
   update enriquecimiento_bdd_pro set ingreso_bruto = @monto, cantidad_empleadores = @cantidad_empleadores where id_ebp = @id_ebp
   end
  else
   begin
   set @monto = (select sum(distinct(remtot)) from empleados where empleados.cuil = @cuit_procesar and periodo = '1712')
   update enriquecimiento_bdd_pro set ingreso_bruto = @monto, cantidad_empleadores = @cantidad_empleadores where id_ebp = @id_ebp

   end
  
   
  FETCH NEXT FROM ProdInfo INTO @cuit_procesar,@id_ebp
 END

CLOSE ProdInfo

DEALLOCATE ProdInfo
END

GO

Used By

No items found