Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
1| Name | Data Type | Length | Description |
|---|---|---|---|
| @cuit | varchar | 20 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
--sp_obtener_telefonos '27208925658'
CREATE OR ALTER PROCEDURE dbo.sp_obtener_telefonos
@cuit varchar(20)
AS
BEGIN
/*
SET NOCOUNT ON;
declare @tel varchar(50),
@email varchar(200),
@tel_formateado varchar(50),
@hay char(1),
@esta int,
@tel_todos varchar(max)
declare @telefonos table ( cuit varchar(20),
telefono varchar(50),
telefono_formateado varchar(50))
DECLARE tel2 CURSOR
FOR
SELECT distinct telefono
FROM telefonos
where id_padron = (select top 1 id_padron from padrones where identificacion = @cuit and habilitado = 1 and identificador in ('CUIT','CUIL'))
OPEN tel2
set @hay = 'N'
FETCH next from tel2 INTO @tel
WHILE (@@FETCH_STATUS <> -1 )
BEGIN
set @hay = 'S'
set @esta = 0
set @esta = (select count(*) from @telefonos where cuit = @cuit and 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 (@cuit,
@tel,
@tel_formateado)
end
FETCH next from tel2 INTO @tel
END
CLOSE tel2
DEALLOCATE tel2
if (@hay = 'N')
begin
insert into @telefonos
values (@cuit,
'',
'')
end
set @tel_todos = ''
DECLARE rest CURSOR
FOR
select telefono_formateado
from @telefonos
where cuit = @cuit
OPEN rest
FETCH next from rest INTO @tel
WHILE (@@FETCH_STATUS <> -1 )
BEGIN
if (@tel != '')
begin
if (@tel_todos = '')
begin
set @tel_todos = @tel
end
else
begin
set @tel_todos = @tel_todos + ' / ' + @tel
end
end
FETCH next from rest INTO @tel
END
CLOSE rest
DEALLOCATE rest
select @cuit as cuit, @tel_todos as telefonos
*/
SET NOCOUNT ON;
declare @tel varchar(50),
@tel_todos varchar(max) = ''
DECLARE tel21 CURSOR
FOR
SELECT distinct telefono
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,'') != ''
OPEN tel21
FETCH next from tel21 INTO @tel
WHILE (@@FETCH_STATUS <> -1 )
BEGIN
if (@tel != '')
begin
if (@tel_todos = '')
begin
set @tel_todos = @tel
end
else
begin
set @tel_todos = @tel_todos + ' / ' + @tel
end
end
FETCH next from tel21 INTO @tel
END
CLOSE tel21
DEALLOCATE tel21
select @cuit as cuit, @tel_todos as telefonos
END
GO
GO
--sp_obtener_telefonos '27208925658'
CREATE OR ALTER PROCEDURE dbo.sp_obtener_telefonos
@cuit varchar(20)
AS
BEGIN
/*
SET NOCOUNT ON;
declare @tel varchar(50),
@email varchar(200),
@tel_formateado varchar(50),
@hay char(1),
@esta int,
@tel_todos varchar(max)
declare @telefonos table ( cuit varchar(20),
telefono varchar(50),
telefono_formateado varchar(50))
DECLARE tel2 CURSOR
FOR
SELECT distinct telefono
FROM telefonos
where id_padron = (select top 1 id_padron from padrones where identificacion = @cuit and habilitado = 1 and identificador in ('CUIT','CUIL'))
OPEN tel2
set @hay = 'N'
FETCH next from tel2 INTO @tel
WHILE (@@FETCH_STATUS <> -1 )
BEGIN
set @hay = 'S'
set @esta = 0
set @esta = (select count(*) from @telefonos where cuit = @cuit and 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 (@cuit,
@tel,
@tel_formateado)
end
FETCH next from tel2 INTO @tel
END
CLOSE tel2
DEALLOCATE tel2
if (@hay = 'N')
begin
insert into @telefonos
values (@cuit,
'',
'')
end
set @tel_todos = ''
DECLARE rest CURSOR
FOR
select telefono_formateado
from @telefonos
where cuit = @cuit
OPEN rest
FETCH next from rest INTO @tel
WHILE (@@FETCH_STATUS <> -1 )
BEGIN
if (@tel != '')
begin
if (@tel_todos = '')
begin
set @tel_todos = @tel
end
else
begin
set @tel_todos = @tel_todos + ' / ' + @tel
end
end
FETCH next from rest INTO @tel
END
CLOSE rest
DEALLOCATE rest
select @cuit as cuit, @tel_todos as telefonos
*/
SET NOCOUNT ON;
declare @tel varchar(50),
@tel_todos varchar(max) = ''
DECLARE tel21 CURSOR
FOR
SELECT distinct telefono
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,'') != ''
OPEN tel21
FETCH next from tel21 INTO @tel
WHILE (@@FETCH_STATUS <> -1 )
BEGIN
if (@tel != '')
begin
if (@tel_todos = '')
begin
set @tel_todos = @tel
end
else
begin
set @tel_todos = @tel_todos + ' / ' + @tel
end
end
FETCH next from tel21 INTO @tel
END
CLOSE tel21
DEALLOCATE tel21
select @cuit as cuit, @tel_todos as telefonos
END
GO