dbo.api_info_telefonos_cuit

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
/*
exec [api_info_telefonos_cuit] '20115960378' 
*/

CREATE OR ALTER PROCEDURE dbo.api_info_telefonos_cuit 
@p_Cuit varchar(20)
AS
BEGIN

    SET NOCOUNT ON;
 declare @tel varchar(50),
   @tel_formateado varchar(50), 
   @esta int
 declare @telefonos table ( telefono varchar(50),
          telefono_formateado varchar(50))
 DECLARE tel2 CURSOR
   FOR
       SELECT distinct d.telefono
    FROM telefonos AS d
         inner join padrones on padrones.id_padron = d.id_padron 
      WHERE padrones.identificacion = @p_Cuit
  
 OPEN tel2 
 FETCH next from tel2 INTO @tel
 WHILE (@@FETCH_STATUS <> -1 )
  BEGIN
   set @esta = 0
   set @esta = (select count(*) from @telefonos where telefono = @tel)
   if (@esta = 0)
   begin
    set @tel_formateado = null
     set @tel_formateado = (select top 1 '('+iif(len(ttt.TLD)<4,'0'+ttt.TLD,ttt.tld) +') '+PRF+'-'+SFJ
                          from TE_tasa_temp ttt where ttt.TEL_N = @tel)
    if (@tel_formateado is null)
    begin
    set @tel_formateado = (select top 1 '('+tpt.prefijo+') '+'15'+tpt.LINEA_SIN_PREFIJO
           from te_personal_temp tpt where tpt.LINEA = @tel)
    end  
    if (@tel_formateado is null)
    begin
     set @tel_formateado = @tel
    end
    insert into @telefonos
    values (@tel,
      @tel_formateado)
   end
   FETCH next from tel2 INTO @tel
  END
 CLOSE tel2
 DEALLOCATE tel2 

 
 select telefono_formateado as telefono 
  from @telefonos
  
end 
GO

Used By

No items found