Guest User

Untitled

a guest
May 30th, 2015
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.41 KB | None | 0 0
  1. CREATE FUNCTION [dbo].[UDF_GenerateSlug]
  2. (  
  3.     @str VARCHAR(100)
  4. )
  5. RETURNS VARCHAR(100)
  6. AS
  7. BEGIN
  8. DECLARE @IncorrectCharLoc SMALLINT
  9. SET @str = LOWER(@str)
  10. SET @IncorrectCharLoc = PATINDEX('%[^0-9a-z ]%',@str)
  11. WHILE @IncorrectCharLoc > 0
  12. BEGIN
  13. SET @str = STUFF(@str,@incorrectCharLoc,1,'')
  14. SET @IncorrectCharLoc = PATINDEX('%[^0-9a-z ]%',@str)
  15. END
  16. SET @str = REPLACE(@str,' ','-')
  17. RETURN @str
  18. END
Advertisement
Add Comment
Please, Sign In to add comment