miércoles, 8 de febrero de 2012
Eliminar palabras repetidas de una fila
CREATE FUNCTION delete_repeated_words
(
@word VARCHAR(300)
)
RETURNS VARCHAR(300)
AS
BEGIN
DECLARE @new_word VARCHAR(300),
@ultimate_word VARCHAR(300),
@k INT,
@b INT
SET @word = LTRIM(@word)
SET @ultimate_word = ''
SET @new_word = ''
WHILE(CHARINDEX(' ', LTRIM(@word)) <> 0)
BEGIN
SET @k = CHARINDEX(' ', LTRIM(@word))
SET @new_word = LEFT(LTRIM(@word), @k)
SET @b = CHARINDEX(@new_word, @ultimate_word)
IF(@b = 0)
SET @ultimate_word = @ultimate_word + @new_word
SET @word = SUBSTRING(LTRIM(@word), @k + 1, LEN(LTRIM(@word)))
END
SET @new_word = LEFT(LTRIM(@word), @k)
SET @b = CHARINDEX(@new_word, @ultimate_word)
IF(@b = 0)
SET @ultimate_word = @ultimate_word + @new_word
RETURN @ultimate_word
END
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario