Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Add to List function (See related posts)

--Adds an element (nvarchar) to the end of a list (nvarchar), after first inserting a delimiter (nvarchar)
ALTER FUNCTION dbo.fnAddToList (@List nvarchar(4000), @New nvarchar(4000), @Del nvarchar(10))
RETURNS nvarchar(4000)
AS  
BEGIN 
	--Treat ''s as NULLs
	SELECT @List = NULLIF(@List, ''), @Del = NULLIF(@Del, ''), @New = NULLIF(@New, '')
  --First try the concatened string, if null then just the list, 
	--if it too is null, just the new element
	RETURN COALESCE(@List + @Del + @New, @List, @New)
END

Oskar Austegard
http://mo.notono.us

You need to create an account or log in to post comments to this site.


Click here to browse all 4858 code snippets

Related Posts