dbo.copyle_final

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.copyle_final

AS
BEGIN
    SET NOCOUNT ON;

 declare @iden varchar(20),
   @provincia varchar(50), 
   @localidad varchar(120),
   @codigo_postal varchar(100),
   @nombre varchar(100),
   @entidad varchar(100)

 DECLARE bn CURSOR

  FOR
   select distinct isnull(ltrim(rtrim(c.identificacion)),'') identificacion,
       isnull(ltrim(rtrim(c.provincia)),'') provincia,
                isnull(ltrim(rtrim(replace(replace(c.localidad,'?',''),'*',''))),'') localidad,
             isnull(c.codigo_postal,'') codigo_postal      
     from copyle_cuits_2018_06 c
       where provincia in ('CATAMARCA',
         'TUCUMAN',
         'LA RIOJA',
         'CORDOBA')
    and fecha_defuncion is null
    and proceso_final is null
    order by provincia desc
    
  OPEN bn 
  Fetch next from bn INTO @iden,
         @provincia,
         @localidad,
         @codigo_postal 

  WHILE (@@FETCH_STATUS <> -1 )
 
  BEGIN 
   set @nombre = null
   set @entidad = null
   select top 1 @nombre = isnull(ltrim(rtrim(replace(replace(nombre_persona,'¥','Ñ'),'-',''))),'') 
      from padrones
      where padrones.identificacion = @iden
        and padrones.habilitado = 1
   insert into copyle_entrega_junio_2018
   select distinct 
     @iden, 
           @nombre, 
     @provincia,
     @localidad,
     isnull(b.nombre, 'NO INFORMADA') as entidad,
     @codigo_postal
      from cendeu
      left join EntidadesBancarias b on id_banco = convert(int,codigo_ent)
      where iden = @iden 
        and vigente = 1
     and CONVERT(int,situacion) = 1
     and created between '2018-04-01 00:00:00' and '2018-06-01 00:00:00'
   union 
   select distinct 
     @iden, 
           @nombre, 
     @provincia,
     @localidad,
     isnull(b.nombre, 'NO INFORMADA') as entidad,
     @codigo_postal
      from cendeu_temp 
      left join EntidadesBancarias b on id_banco = convert(int,codigo_ent)
      where iden = @iden 
        and vigente = 1
     and CONVERT(int,situacion) = 1
     and created between '2018-04-01 00:00:00' and '2018-06-01 00:00:00'

      update copyle_cuits_2018_06 
      set proceso_final = 1 
    where identificacion = @iden 
      and provincia = @provincia  
            
   Fetch next from bn INTO @iden,
         @provincia,
         @localidad,
         @codigo_postal 

  END
  
  CLOSE bn
  DEALLOCATE bn
END 

GO

Used By

No items found