dbo.sp_obtener_telefonos_tipo

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

4
Name Data Type Length Description
@cuit varchar 20
@fijo varchar -1
@movil varchar -1
@otro varchar -1

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO

/*
DECLARE @fijo VARCHAR(max), @movil varchar(max), @otro varchar(max) 
EXEC [sp_obtener_telefonos_tipo] '27208925658',  @fijo output, @movil output, @otro output 
select @fijo , @movil , @otro  
*/


CREATE OR ALTER PROCEDURE dbo.sp_obtener_telefonos_tipo  
@cuit  varchar(20), 
@fijo  varchar(max) = '' output,
@movil varchar(max) = '' output,
@otro  varchar(max) = '' output
AS
BEGIN
 SET NOCOUNT ON;
 declare @tel varchar(50),
   @tipo varchar(50), 
   @tel_fijo  varchar(max) = '',
   @tel_movil varchar(max) = '',
   @tel_otro  varchar(max) = '' 
   

 DECLARE tel21 CURSOR
  FOR
     SELECT distinct telefono, tipo
   FROM telefonos 
      where id_padron = (select top 1 id_padron from padrones where identificacion = @cuit and habilitado = 1 and identificador in (select identificador from identificadores where country_code = 'AR'))
   and isnull(telefono,'') != ''
   order by tipo
 OPEN tel21
 FETCH next from tel21 INTO @tel, @tipo
 WHILE (@@FETCH_STATUS <> -1 )
 BEGIN
  if (@tel != '') begin
    if @tel like '15%' set @tipo = 'MOVIL'
    if (@tipo = 'FIJO')  set @tel_fijo = @tel_fijo + ' / ' + @tel
    else 
    if (@tipo = 'MOVIL') set @tel_movil = @tel_movil + ' / ' + @tel
    else 
    set @tel_otro = @tel_otro + ' / ' + @tel
  end 
  FETCH next from tel21 INTO @tel, @tipo
 END 
  CLOSE tel21
  DEALLOCATE tel21
  
  set @fijo  = STUFF ( @tel_fijo, 1 , 3 , '') 
  set @movil = STUFF ( @tel_movil, 1 , 3 , '') 
  set @otro  = STUFF ( @tel_otro, 1 , 3 , '')  
END 
GO