dbo.sp_compara_nombres

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

2
Name Data Type Length Description
@Nom1 varchar 70
@Nom2 varchar 70

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
-- =============================================
-- Author: María Inés Soria
-- Create date: 2017-12-05
-- Description: Ingresa 2 Nombres, devuelve '1' si hay mas de dos palabras iguales, '0' si no
-- =============================================
-- sp_compara_nombres 'SORIA MARIA INES', 'MARIA INES SORIA'
CREATE OR ALTER PROCEDURE dbo.sp_compara_nombres
@Nom1 VARCHAR(70),
@Nom2 VARCHAR(70)

AS
BEGIN

 declare @palabra_1 table (palabra varchar(30))
 declare @palabra_2 table (palabra varchar(30))
 declare @pal1 varchar(30), @pal2 varchar(30)
 declare @cant_iguales int = 0

 insert into @palabra_1
   exec sp_separo_nombres @Nom1

 insert into @palabra_2
   exec sp_separo_nombres @Nom2

 DECLARE bn CURSOR FOR
 select upper(palabra) from @palabra_1
 OPEN bn 
 Fetch next from bn INTO @pal1
 WHILE (@@FETCH_STATUS <> -1 )
 BEGIN

  DECLARE bn2 CURSOR FOR
  select upper(palabra) from @palabra_2
  OPEN bn2 
  Fetch next from bn2 INTO @pal2
  WHILE (@@FETCH_STATUS <> -1 )
  BEGIN
      if (@pal2 = @pal1) begin set @cant_iguales = @cant_iguales + 1 end 
   Fetch next from bn2 INTO @pal2
  END 
  CLOSE bn2
  DEALLOCATE bn2 

  Fetch next from bn INTO @pal1
 END 
 CLOSE bn
 DEALLOCATE bn 

 if (@cant_iguales >= 2) 
 begin
  return 1
 end 
 else
 begin
  return 0 
 end 
END 

GO

Depends On

1