/ Published in: SQL
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: <Author,,Name> -- Create date: <Create Date,,> -- Description: <Description,,> -- ============================================= ALTER PROCEDURE dbo.CrearURLNoticias AS BEGIN DECLARE @titulo VARCHAR(500),@titulofinal nvarchar(255), @s1 nvarchar(255),@s2 nvarchar(255), @anterior nvarchar(1), @nuevo nvarchar(1) ,@iter INT,@permitidos nvarchar(255) SET @s1= 'ÃÂÃÄÉÊËÃÃŽÃÓÕÔÖÙÛÚÜà áäâãèéëêîìïÃòöóõôùûúü' SET @s2 = 'AAAAEEEIIIOOOOUUUUaaaaaeeeeiiiiooooouuuu' SET @permitidos='abcdefghjklmnopqrstuvwxyz0123456789-' DECLARE Datos CURSOR FOR SELECT title FROM NewsPages WHERE titleUrl IS NULL OR ltrim(rtrim(titleUrl)) ='' OPEN Datos FETCH NEXT FROM Datos INTO @titulo WHILE ((@@FETCH_STATUS = 0)) BEGIN SET @titulofinal=@titulo SET @titulofinal=Ltrim(RTrim(@titulofinal)) SET @titulofinal=REPLACE(@titulofinal,' ','-') SET @titulofinal=REPLACE(@titulofinal,'ñ','nh') SET @titulofinal=REPLACE(@titulofinal,'á','a') SET @titulofinal=REPLACE(@titulofinal,'é','e') SET @titulofinal=REPLACE(@titulofinal,'í','i') SET @titulofinal=REPLACE(@titulofinal,'ó','o') SET @titulofinal=REPLACE(@titulofinal,'ú','u') SET @titulofinal=REPLACE(@titulofinal,'ñ','nh') SET @iter = 0 IF (len(@titulofinal) != 0) BEGIN WHILE @iter<len(@s1) BEGIN SET @anterior = SUBSTRING(@s1,@iter,1); SET @nuevo = SUBSTRING(@s2,@iter,1); SET @titulofinal = REPLACE(@titulofinal,@anterior, @nuevo); SET @iter=@iter+1 END END SET @titulofinal=LOWER(@titulofinal) While PatIndex('%[^a-zA-Z0-9 -]%', @titulofinal) > 0 SET @titulofinal = Stuff(@titulofinal, PatIndex('%[^a-zA-Z0-9 -]%', @titulofinal), 1, '') print @titulofinal FETCH NEXT FROM Datos INTO @titulo END CLOSE Datos DEALLOCATE Datos END GO