Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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