﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Discuss content posted by ~~Hari.Bagra / Article Discussions by Author  / Function to  Split Multivalued Parameter / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Fri, 24 May 2013 04:48:41 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Function to  Split Multivalued Parameter</title><link>http://www.sqlservercentral.com/Forums/Topic402324-555-1.aspx</link><description>And you will find a better one here: [b][url]http://www.sqlservercentral.com/articles/Tally+Table/72993/[/url][/b].</description><pubDate>Mon, 16 Jul 2012 11:21:14 GMT</pubDate><dc:creator>Lynn Pettis</dc:creator></item><item><title>RE: Function to  Split Multivalued Parameter</title><link>http://www.sqlservercentral.com/Forums/Topic402324-555-1.aspx</link><description>Here's a FAST function that avoids using a loop and uses a clustered index seek on the output table by adding a primary key and using that in the WHERE clause. I did not develop the idea to use the XML split myself...I found it some time ago from a Google search and can't give a proper reference to the developer. If anyone knows who came up with it and can give proper credit, please do.[code]CREATE FUNCTION dbo.tvfParseDelimitedString     (     @S NVARCHAR(MAX)    -- Delimited input string    ,@Split CHAR(1)      -- Delimiter used for the input string    )RETURNS @Table TABLE     (     [ID] INT NOT NULL IDENTITY(1,1)    ,[Value] NVARCHAR(MAX) NULL    ,PRIMARY KEY ([ID])    ,UNIQUE ([ID])    )BEGIN    DECLARE @X XML    SET @X = CONVERT(XML,'&amp;lt;root&amp;gt;&amp;lt;s&amp;gt;' + REPLACE(@S,@Split,'&amp;lt;/s&amp;gt;&amp;lt;s&amp;gt;')+'&amp;lt;/s&amp;gt;&amp;lt;/root&amp;gt;')        INSERT INTO @Table    SELECT T.c.value('.','NVARCHAR(MAX)') AS [Value]    FROM @X.nodes('/root/s') T (c)    RETURN         /*     SELECT [Value]     FROM dbo.tvfParseDelimitedString(N'1,AAA,4,BB,777,XYZ',',')     WHERE [ID] &amp;gt; 0     */ENDGO[/code]</description><pubDate>Mon, 16 Jul 2012 10:14:25 GMT</pubDate><dc:creator>Steven Willis</dc:creator></item><item><title>RE: Function to  Split Multivalued Parameter</title><link>http://www.sqlservercentral.com/Forums/Topic402324-555-1.aspx</link><description>A much more efficient version is available here,[url=http://philcart.blogspot.com/2007/06/split-function.html]http://philcart.blogspot.com/2007/06/split-function.html[/url]It uses varchar(max), so you're not limited in how many values are passed. Doesn't use a loop, so the number of values passed doesn't affect performance.</description><pubDate>Wed, 10 Oct 2007 21:50:08 GMT</pubDate><dc:creator>philcart</dc:creator></item><item><title>Function to  Split Multivalued Parameter</title><link>http://www.sqlservercentral.com/Forums/Topic402324-555-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/scripts/Miscellaneous/31971/"&gt;Function to  Split Multivalued Parameter&lt;/A&gt;[/B]</description><pubDate>Mon, 24 Sep 2007 19:53:44 GMT</pubDate><dc:creator>Hari.Sharma</dc:creator></item></channel></rss>