dbo.api_idphone

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

1
Name Data Type Length Description
@telefono varchar 200

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
-- =============================================
-- Author: Marita Soria
-- Create date: 13/02/2023
-- Description: trae los identificacion, nombre_persona, cuerpo_clave que corresponde al telefono
-- =============================================
/*
exec api_idphone '115'
select * from telefonos where telefono = '1150' or telefono_limpio = '1150'
*/

CREATE OR ALTER PROCEDURE dbo.api_idphone
 @telefono varchar(200) 
AS
BEGIN
 SET NOCOUNT ON;
 declare @telefono2 varchar(200)
 -- solo deja los numeros 
 select @telefono = ltrim(rtrim(dbo.fn_StripCharacters(@telefono, '^0-9/')))
 if (@telefono not like '0%')
    set @telefono2 = '0' + @telefono 
 else 
  set @telefono2 = (select ltrim(rtrim(SUBSTRING(@telefono,2,200))))
 
 SELECT distinct identificacion, nombre_persona, cuerpo_clave 
 from telefonos 
 inner join padrones on padrones.id_padron = telefonos.id_padron 
 where telefono_limpio in (@telefono)
 
 union 
 
 SELECT distinct identificacion, nombre_persona, cuerpo_clave 
 from telefonos 
 inner join padrones on padrones.id_padron = telefonos.id_padron 
 where telefono in (@telefono) 
 
 
END

/* En telefono_limpio sacamos los caracteres de telefono (menos los numeros y la /)
declare @id int 
declare @telefono varchar(500) 
DECLARE C_tel CURSOR FOR
select TOP 10000  id_telefono,telefono    
  from telefonos  
 where telefono_limpio is null and ISNUMERIC(telefono) = 0
OPEN C_tel
FETCH NEXT FROM C_tel INTO @id, @telefono 
WHILE @@fetch_status = 0
BEGIN 
update telefonos set telefono_limpio = ltrim(rtrim(dbo.fn_StripCharacters(telefono, '^0-9/'))) where id_telefono = @id and telefono = @telefono
FETCH NEXT FROM C_tel INTO @id, @telefono 
END 
CLOSE C_tel
DEALLOCATE C_tel

*/

GO

Used By

No items found