Generate the formatted URL from title like blog, article etc in SQL Server

======Create Function

CREATE FUNCTION [dbo].[GenerateMapKey] (@keyText NVARCHAR(4000))
RETURNS NVARCHAR(4000)
AS
BEGIN
DECLARE @mapKey VARCHAR(4000)

SELECT @mapKey = LOWER(@keyText)

SELECT @mapKey = REPLACE(@mapKey,' ','-')
SELECT @mapKey = REPLACE(@mapKey, CHAR(39),'-')
SELECT @mapKey = REPLACE(@mapKey,'’','-')
SELECT @mapKey = REPLACE(@mapKey,'‘','-')
SELECT @mapKey = REPLACE(@mapKey,'!','-')
SELECT @mapKey = REPLACE(@mapKey,'#','-')
SELECT @mapKey = REPLACE(@mapKey,'$','-')
SELECT @mapKey = REPLACE(@mapKey,'%','-')
SELECT @mapKey = REPLACE(@mapKey,'^','-')
SELECT @mapKey = REPLACE(@mapKey,'&','-')
SELECT @mapKey = REPLACE(@mapKey,'*','-')
SELECT @mapKey = REPLACE(@mapKey,'(','-')
SELECT @mapKey = REPLACE(@mapKey,')','-')
SELECT @mapKey = REPLACE(@mapKey,'+','-')
SELECT @mapKey = REPLACE(@mapKey,'=','-')
SELECT @mapKey = REPLACE(@mapKey,',','-')
SELECT @mapKey = REPLACE(@mapKey,'.','-')
SELECT @mapKey = REPLACE(@mapKey,'/','-')
SELECT @mapKey = REPLACE(@mapKey,'?','-')
SELECT @mapKey = REPLACE(@mapKey,':','-')
SELECT @mapKey = REPLACE(@mapKey,';','-')
SELECT @mapKey = REPLACE(@mapKey,'''','')
SELECT @mapKey = REPLACE(@mapKey,'"','-')
SELECT @mapKey = REPLACE(@mapKey,'_','-')
SELECT @mapKey = REPLACE(@mapKey,'[','-')
SELECT @mapKey = REPLACE(@mapKey,']','-')
SELECT @mapKey = REPLACE(@mapKey,'{','-')
SELECT @mapKey = REPLACE(@mapKey,'}','-')
SELECT @mapKey = REPLACE(@mapKey,'\','-')
SELECT @mapKey = REPLACE(@mapKey,'|','-')

SELECT @mapKey = REPLACE(@mapKey,'-----------','-')
SELECT @mapKey = REPLACE(@mapKey,'----------','-')
SELECT @mapKey = REPLACE(@mapKey,'---------','-')
SELECT @mapKey = REPLACE(@mapKey,'--------','-')
SELECT @mapKey = REPLACE(@mapKey,'-------','-')
SELECT @mapKey = REPLACE(@mapKey,'------','-')
SELECT @mapKey = REPLACE(@mapKey,'-----','-')
SELECT @mapKey = REPLACE(@mapKey,'----','-')
SELECT @mapKey = REPLACE(@mapKey,'---','-')
SELECT @mapKey = REPLACE(@mapKey,'--','-')
SELECT @mapKey = REPLACE(@mapKey,'--','-')
SELECT @mapKey = REPLACE(@mapKey,'--','-')
SELECT @mapKey = REPLACE(@mapKey,'--','-')
SELECT @mapKey = REPLACE(@mapKey,'--','-')
SELECT @mapKey = REPLACE(@mapKey,'--','-')


IF LEFT(@mapKey,1) = '-'
SELECT @mapKey = RIGHT(@mapKey,LEN(@mapKey)-1)
IF RIGHT(@mapKey,1) = '-'
SELECT @mapKey = LEFT(@mapKey,LEN(@mapKey)-1)

SELECT @mapKey = REPLACE(@mapKey,'--','-')
SELECT @mapKey = REPLACE(@mapKey,'--','-')
SELECT @mapKey = REPLACE(@mapKey,'--','-')
SELECT @mapKey = REPLACE(@mapKey,'--','-')
SELECT @mapKey = REPLACE(@mapKey,'--','-')
SELECT @mapKey = REPLACE(@mapKey,'--','-')
SELECT @mapKey = REPLACE(@mapKey,'--','-')
SELECT @mapKey = REPLACE(@mapKey,'--','-')


-- SELECT @mapKey = LOWER(@mapKey)

RETURN @mapKey

END

============= OUTPUT





Comments

Popular posts from this blog

GROUP BY, CUBE, ROLLUP and SQL SERVER 2005

How to get content of Ckeditor & Fckeditor using Javascript

How to Fix Error- Sys.WebForms.PageRequestManagerTimeoutException - The server request timed out