Skip to content

Instantly share code, notes, and snippets.

@erraggy
Created May 26, 2011 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save erraggy/992647 to your computer and use it in GitHub Desktop.
Save erraggy/992647 to your computer and use it in GitHub Desktop.
Scalar function to convert a post title into a URL slug
CREATE FUNCTION [dbo].[make_slug]
(
@post_title nvarchar(256)
)
RETURNS nvarchar(500)
AS
BEGIN
-- Declare the return variable here
DECLARE @slug nvarchar(500)
DECLARE @clean_title nvarchar(500)
SET @clean_title = LOWER(dbo.deDupeSpaces(dbo.removePunctuation(@post_title)))
SET @slug = REPLACE(@clean_title, ' ', '-')
RETURN @slug
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment