CREATE FUNCTION [dbo].[fnStringQuote]
(
@string NVARCHAR(MAX),
@delimiter CHAR(1)
)
RETURNS NVARCHAR(MAX)
BEGIN
DECLARE @strPart VARCHAR(255)
SET @strPart = char(39)+','+ char(39)
SET @string = replace(@string,@delimiter,@strPart)
SET @string = char(39) + @string + char(39)
RETURN @string
END