<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; UDF &#8211; Function to Convert List to Table</title>
	<atom:link href="http://blog.sqlauthority.com/2007/05/06/sql-server-udf-function-to-convert-list-to-table/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2007/05/06/sql-server-udf-function-to-convert-list-to-table/</link>
	<description>Notes of a SQL Server MVP and Database Administrator</description>
	<lastBuildDate>Sat, 21 Nov 2009 05:54:09 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: David</title>
		<link>http://blog.sqlauthority.com/2007/05/06/sql-server-udf-function-to-convert-list-to-table/#comment-54820</link>
		<dc:creator>David</dc:creator>
		<pubDate>Thu, 13 Aug 2009 12:49:48 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/06/sql-server-udf-function-to-convert-list-to-table/#comment-54820</guid>
		<description>Thank you for this!  It really was useful for me, as I wanted to be able to return an Max and a Sum of a group for items that were being calculated, appearing in a single row. 

I changed your function to have the Item be a float, and  then used the convert function to pass the variables in:

Select Val1, Val2, Val3, Val4, 
(
Select Max(Item) From dbo.udf_List2Table(Convert(varchar(20),Val1) + &#039;,&#039; + Convert(varchar(20),Val2) + &#039;,&#039; +  + Convert(varchar(20),Val3) + &#039;,&#039; +  + Convert(varchar(20),val4) + &#039;,&#039;,&#039;,&#039;)
) as MaxVal
From tbl</description>
		<content:encoded><![CDATA[<p>Thank you for this!  It really was useful for me, as I wanted to be able to return an Max and a Sum of a group for items that were being calculated, appearing in a single row. </p>
<p>I changed your function to have the Item be a float, and  then used the convert function to pass the variables in:</p>
<p>Select Val1, Val2, Val3, Val4,<br />
(<br />
Select Max(Item) From dbo.udf_List2Table(Convert(varchar(20),Val1) + &#8216;,&#8217; + Convert(varchar(20),Val2) + &#8216;,&#8217; +  + Convert(varchar(20),Val3) + &#8216;,&#8217; +  + Convert(varchar(20),val4) + &#8216;,&#8217;,',&#8217;)<br />
) as MaxVal<br />
From tbl</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: phani</title>
		<link>http://blog.sqlauthority.com/2007/05/06/sql-server-udf-function-to-convert-list-to-table/#comment-54394</link>
		<dc:creator>phani</dc:creator>
		<pubDate>Mon, 03 Aug 2009 15:41:16 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/06/sql-server-udf-function-to-convert-list-to-table/#comment-54394</guid>
		<description>Thanks a ton Dave, I have got stupid extension for more lists of csv into single table :)
CREATE FUNCTION dbo.udf_Lists2Table
(
@List1 VARCHAR(MAX),
@List2 VARCHAR(MAX),
@List3 VARCHAR(MAX),
@Delim CHAR
)
RETURNS
@ParsedList TABLE
(
item1 VARCHAR(MAX),
item2 VARCHAR(MAX),
item3 VARCHAR(MAX)
)
AS
BEGIN
DECLARE @item1 VARCHAR(MAX), @Pos1 INT,
@item2 VARCHAR(MAX), @Pos2 INT,
@item3 VARCHAR(MAX), @Pos3 INT
SET @List1 = LTRIM(RTRIM(@List1))+ @Delim
SET @List2 = LTRIM(RTRIM(@List2))+ @Delim
SET @List3 = LTRIM(RTRIM(@List3))+ @Delim
SET @Pos1 = CHARINDEX(@Delim, @List1, 1)
SET @Pos2 = CHARINDEX(@Delim, @List2, 1)
SET @Pos3 = CHARINDEX(@Delim, @List3, 1)
WHILE (@Pos1 &gt; 0 AND @Pos2 &gt; 0 AND @Pos2 &gt; 0)
BEGIN
SET @item1 = LTRIM(RTRIM(LEFT(@List1, @Pos1 - 1)))
SET @item2 = LTRIM(RTRIM(LEFT(@List2, @Pos2 - 1)))
SET @item3 = LTRIM(RTRIM(LEFT(@List3, @Pos3 - 1)))
IF @item1 = &#039;&#039;
BEGIN
 SET @item1 = NULL
END
IF @item2 = &#039;&#039;
BEGIN
 SET @item2 = NULL
END
IF @item3 = &#039;&#039;
BEGIN
 SET @item3 = NULL
END
INSERT INTO @ParsedList (item1, item2, item3)
VALUES (CAST(@item1 AS VARCHAR(MAX)), CAST(@item2 AS VARCHAR(MAX)), CAST(@item3 AS VARCHAR(MAX)))
SET @List1 = RIGHT(@List1, LEN(@List1) - @Pos1)
SET @List2 = RIGHT(@List2, LEN(@List2) - @Pos2)
SET @List3 = RIGHT(@List3, LEN(@List3) - @Pos3)
SET @Pos1 = CHARINDEX(@Delim, @List1, 1)
SET @Pos2 = CHARINDEX(@Delim, @List2, 1)
SET @Pos3 = CHARINDEX(@Delim, @List3, 1)
END
RETURN
END
GO

select * from udf_List2Table(&#039;1, ,3&#039;,&#039;a,b,c&#039;,&#039;x, ,z&#039;, &#039;,&#039;)</description>
		<content:encoded><![CDATA[<p>Thanks a ton Dave, I have got stupid extension for more lists of csv into single table :)<br />
CREATE FUNCTION dbo.udf_Lists2Table<br />
(<br />
@List1 VARCHAR(MAX),<br />
@List2 VARCHAR(MAX),<br />
@List3 VARCHAR(MAX),<br />
@Delim CHAR<br />
)<br />
RETURNS<br />
@ParsedList TABLE<br />
(<br />
item1 VARCHAR(MAX),<br />
item2 VARCHAR(MAX),<br />
item3 VARCHAR(MAX)<br />
)<br />
AS<br />
BEGIN<br />
DECLARE @item1 VARCHAR(MAX), @Pos1 INT,<br />
@item2 VARCHAR(MAX), @Pos2 INT,<br />
@item3 VARCHAR(MAX), @Pos3 INT<br />
SET @List1 = LTRIM(RTRIM(@List1))+ @Delim<br />
SET @List2 = LTRIM(RTRIM(@List2))+ @Delim<br />
SET @List3 = LTRIM(RTRIM(@List3))+ @Delim<br />
SET @Pos1 = CHARINDEX(@Delim, @List1, 1)<br />
SET @Pos2 = CHARINDEX(@Delim, @List2, 1)<br />
SET @Pos3 = CHARINDEX(@Delim, @List3, 1)<br />
WHILE (@Pos1 &gt; 0 AND @Pos2 &gt; 0 AND @Pos2 &gt; 0)<br />
BEGIN<br />
SET @item1 = LTRIM(RTRIM(LEFT(@List1, @Pos1 &#8211; 1)))<br />
SET @item2 = LTRIM(RTRIM(LEFT(@List2, @Pos2 &#8211; 1)))<br />
SET @item3 = LTRIM(RTRIM(LEFT(@List3, @Pos3 &#8211; 1)))<br />
IF @item1 = &#8221;<br />
BEGIN<br />
 SET @item1 = NULL<br />
END<br />
IF @item2 = &#8221;<br />
BEGIN<br />
 SET @item2 = NULL<br />
END<br />
IF @item3 = &#8221;<br />
BEGIN<br />
 SET @item3 = NULL<br />
END<br />
INSERT INTO @ParsedList (item1, item2, item3)<br />
VALUES (CAST(@item1 AS VARCHAR(MAX)), CAST(@item2 AS VARCHAR(MAX)), CAST(@item3 AS VARCHAR(MAX)))<br />
SET @List1 = RIGHT(@List1, LEN(@List1) &#8211; @Pos1)<br />
SET @List2 = RIGHT(@List2, LEN(@List2) &#8211; @Pos2)<br />
SET @List3 = RIGHT(@List3, LEN(@List3) &#8211; @Pos3)<br />
SET @Pos1 = CHARINDEX(@Delim, @List1, 1)<br />
SET @Pos2 = CHARINDEX(@Delim, @List2, 1)<br />
SET @Pos3 = CHARINDEX(@Delim, @List3, 1)<br />
END<br />
RETURN<br />
END<br />
GO</p>
<p>select * from udf_List2Table(&#8216;1, ,3&#8242;,&#8217;a,b,c&#8217;,'x, ,z&#8217;, &#8216;,&#8217;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER - Function to Convert List to Table Journey to SQL Authority with Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2007/05/06/sql-server-udf-function-to-convert-list-to-table/#comment-45765</link>
		<dc:creator>SQL SERVER - Function to Convert List to Table Journey to SQL Authority with Pinal Dave</dc:creator>
		<pubDate>Tue, 20 Jan 2009 07:43:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/06/sql-server-udf-function-to-convert-list-to-table/#comment-45765</guid>
		<description>[...] February 10, 2007 by pinaldave    Update : (5/5/2007) I have updated the UDF to support SQL SERVER 2005.  Visit :SQL SERVER - UDF - Function to Convert List to Table [...]</description>
		<content:encoded><![CDATA[<p>[...] February 10, 2007 by pinaldave    Update : (5/5/2007) I have updated the UDF to support SQL SERVER 2005.  Visit :SQL SERVER &#8211; UDF &#8211; Function to Convert List to Table [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER - Function to Convert List to Table Journey to SQL Authority with Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2007/05/06/sql-server-udf-function-to-convert-list-to-table/#comment-45742</link>
		<dc:creator>SQL SERVER - Function to Convert List to Table Journey to SQL Authority with Pinal Dave</dc:creator>
		<pubDate>Mon, 19 Jan 2009 19:05:42 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/06/sql-server-udf-function-to-convert-list-to-table/#comment-45742</guid>
		<description>[...] February 10, 2007 by pinaldave    Update : (5/5/2007) I have updated the UDF to support SQL SERVER 2005.  Visit :SQL SERVER - UDF - Function to Convert List to Table [...]</description>
		<content:encoded><![CDATA[<p>[...] February 10, 2007 by pinaldave    Update : (5/5/2007) I have updated the UDF to support SQL SERVER 2005.  Visit :SQL SERVER &#8211; UDF &#8211; Function to Convert List to Table [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ad</title>
		<link>http://blog.sqlauthority.com/2007/05/06/sql-server-udf-function-to-convert-list-to-table/#comment-41626</link>
		<dc:creator>Ad</dc:creator>
		<pubDate>Tue, 12 Aug 2008 23:48:09 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/06/sql-server-udf-function-to-convert-list-to-table/#comment-41626</guid>
		<description>I am relatively new to SQL, this code from Sudev gandhi works great, but can someone please explain how this works...

DECLARE @commaSeparatedVal AS VARCHAR(MAX);
SELECT @commaSeparatedVal = ISNULL(@commaSeparatedVal +’,&#039;,”) + CONVERT(VARCHAR,[SKU]) FROM PRODUCT
PRINT @commaSeparatedVal</description>
		<content:encoded><![CDATA[<p>I am relatively new to SQL, this code from Sudev gandhi works great, but can someone please explain how this works&#8230;</p>
<p>DECLARE @commaSeparatedVal AS VARCHAR(MAX);<br />
SELECT @commaSeparatedVal = ISNULL(@commaSeparatedVal +’,&#8217;,”) + CONVERT(VARCHAR,[SKU]) FROM PRODUCT<br />
PRINT @commaSeparatedVal</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sudev Gandhi</title>
		<link>http://blog.sqlauthority.com/2007/05/06/sql-server-udf-function-to-convert-list-to-table/#comment-38887</link>
		<dc:creator>Sudev Gandhi</dc:creator>
		<pubDate>Fri, 30 May 2008 10:58:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/06/sql-server-udf-function-to-convert-list-to-table/#comment-38887</guid>
		<description>Hi Jayaram &amp; HAGster,

I guess what you people need is from a table you need to combine all the values in single field e.g. from PRODUCT table you want list of [SKU] column in &#039;,&#039; separated list. for that you can use following T-SQL snippet.

    DECLARE @commaSeparatedVal AS VARCHAR(MAX);
    SELECT @commaSeparatedVal = ISNULL(@commaSeparatedVal +&#039;,&#039;,&#039;&#039;) + CONVERT(VARCHAR,[SKU]) FROM PRODUCT
    PRINT @commaSeparatedVal

Now you can fire

SELECT CAST(item AS INT) AS Example2
FROM dbo.udf_List2Table(@commaSeparatedVal,’,&#039;)

ref: http://sudev.blogspot.com/2008/05/comma-separated-list-of-values-of.html</description>
		<content:encoded><![CDATA[<p>Hi Jayaram &amp; HAGster,</p>
<p>I guess what you people need is from a table you need to combine all the values in single field e.g. from PRODUCT table you want list of [SKU] column in &#8216;,&#8217; separated list. for that you can use following T-SQL snippet.</p>
<p>    DECLARE @commaSeparatedVal AS VARCHAR(MAX);<br />
    SELECT @commaSeparatedVal = ISNULL(@commaSeparatedVal +&#8217;,',&#8221;) + CONVERT(VARCHAR,[SKU]) FROM PRODUCT<br />
    PRINT @commaSeparatedVal</p>
<p>Now you can fire</p>
<p>SELECT CAST(item AS INT) AS Example2<br />
FROM dbo.udf_List2Table(@commaSeparatedVal,’,&#8217;)</p>
<p>ref: <a href="http://sudev.blogspot.com/2008/05/comma-separated-list-of-values-of.html" rel="nofollow">http://sudev.blogspot.com/2008/05/comma-separated-list-of-values-of.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: HAGster</title>
		<link>http://blog.sqlauthority.com/2007/05/06/sql-server-udf-function-to-convert-list-to-table/#comment-37624</link>
		<dc:creator>HAGster</dc:creator>
		<pubDate>Mon, 12 May 2008 14:58:23 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/06/sql-server-udf-function-to-convert-list-to-table/#comment-37624</guid>
		<description>For Jamaram
Just in case your reading this Jamaram, I did a little work around to accomplish what you needed.
Declare a varable and select your comma separated list into in then run the function against the varable like below.

If this is any help then im glad, and im not very good at SQL so I have no idea if this is a messy way to do it etc.


Declare @yourlist char(800)
select @yourlist = (SELECT itemlist FROM tablename WHERE id = 1 )


SELECT item AS Example1
    FROM dbo.udf_List2Table(@yourlist,&#039;,&#039;)
GO


Kind Regards Guy</description>
		<content:encoded><![CDATA[<p>For Jamaram<br />
Just in case your reading this Jamaram, I did a little work around to accomplish what you needed.<br />
Declare a varable and select your comma separated list into in then run the function against the varable like below.</p>
<p>If this is any help then im glad, and im not very good at SQL so I have no idea if this is a messy way to do it etc.</p>
<p>Declare @yourlist char(800)<br />
select @yourlist = (SELECT itemlist FROM tablename WHERE id = 1 )</p>
<p>SELECT item AS Example1<br />
    FROM dbo.udf_List2Table(@yourlist,&#8217;,')<br />
GO</p>
<p>Kind Regards Guy</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: HAGster</title>
		<link>http://blog.sqlauthority.com/2007/05/06/sql-server-udf-function-to-convert-list-to-table/#comment-37621</link>
		<dc:creator>HAGster</dc:creator>
		<pubDate>Mon, 12 May 2008 14:44:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/06/sql-server-udf-function-to-convert-list-to-table/#comment-37621</guid>
		<description>Was woundering the same myself Jayaram, did you work out how to use the function against SELECTED data?

Kind Regards Guy</description>
		<content:encoded><![CDATA[<p>Was woundering the same myself Jayaram, did you work out how to use the function against SELECTED data?</p>
<p>Kind Regards Guy</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jayaram</title>
		<link>http://blog.sqlauthority.com/2007/05/06/sql-server-udf-function-to-convert-list-to-table/#comment-35232</link>
		<dc:creator>jayaram</dc:creator>
		<pubDate>Mon, 21 Apr 2008 08:25:13 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/06/sql-server-udf-function-to-convert-list-to-table/#comment-35232</guid>
		<description>Thanks !! It works fine with data passed as parameter...
But how to substitute a column name instead of the raw data in the UDF. I tried but in vain...   I mean...   

SELECT CAST(item AS INT) AS Example2
FROM dbo.udf_List2Table(select canview from table3,&#039;,&#039;)
GO

gives the error message. Incorrect syntax near &quot;select&quot;

pL help.!</description>
		<content:encoded><![CDATA[<p>Thanks !! It works fine with data passed as parameter&#8230;<br />
But how to substitute a column name instead of the raw data in the UDF. I tried but in vain&#8230;   I mean&#8230;   </p>
<p>SELECT CAST(item AS INT) AS Example2<br />
FROM dbo.udf_List2Table(select canview from table3,&#8217;,')<br />
GO</p>
<p>gives the error message. Incorrect syntax near &#8220;select&#8221;</p>
<p>pL help.!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
