<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ralf Eisenreich &#187; snippets</title>
	<atom:link href="http://sqlblog.de/blog/tag/snippets/feed/" rel="self" type="application/rss+xml" />
	<link>http://sqlblog.de/blog</link>
	<description>SQLBlog.DE &#124; ..things to remember</description>
	<lastBuildDate>Mon, 26 Dec 2011 14:37:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>T-SQL: Split column in several rows</title>
		<link>http://sqlblog.de/blog/2009/04/t-sql-split-column-in-several-rows/</link>
		<comments>http://sqlblog.de/blog/2009/04/t-sql-split-column-in-several-rows/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 14:10:39 +0000</pubDate>
		<dc:creator>Ralf</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[snippets]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://sqlblog.de/blog/?p=550</guid>
		<description><![CDATA[problem If I have a column with several values (separated by CR) which I need separated into rows then following...]]></description>
			<content:encoded><![CDATA[<p><strong>problem</strong><br />
If I have a column with several values (separated by CR) which I need separated into rows then following solution can help:</p>
<p><strong>possible solution: T-SQL</strong><br />
One possible solution using T-SQL is following statement.<br />
The function <code>fn_Split</code> returns all values in a list and the <code>replace</code> function converts the CR (carriage returns) to commas.</p>
<p><code><br />
SELECT<br />
[Key]<br />
,[b.Value]<br />
,[c.Value]<br />
FROM<br />
[dbo.TableExcel] AS a<br />
CROSS APPLY<br />
fn_Split(REPLACE(a.Persons, CHAR(10)+CHAR(13),','), ',') AS b<br />
CROSS APPLY<br />
fn_Split(REPLACE(a.Departments, CHAR(10)+CHAR(13),','), ',') AS c<br />
</code></p>
<p>The corresponding <code>fn_Split</code> function:<br />
<code><br />
CREATE FUNCTION [dbo].[fn_Split](@text nvarchar(max), @delimiter char(1) = ' ')<br />
RETURNS @Strings TABLE (<br />
position int IDENTITY PRIMARY KEY,<br />
value nvarchar(max)<br />
)<br />
AS<br />
BEGIN<br />
DECLARE @index int<br />
SET @index = -1<br />
WHILE (LEN(@text) &gt; 0)<br />
BEGIN<br />
SET @index = CHARINDEX(@delimiter , @text)<br />
IF (@index = 0) AND (LEN(@text) &gt; 0)<br />
BEGIN<br />
INSERT INTO @Strings VALUES (@text)<br />
BREAK<br />
END<br />
IF (@index &gt; 1)<br />
BEGIN<br />
INSERT INTO @Strings<br />
VALUES (LEFT(@text, @index - 1))<br />
SET @text = RIGHT(@text, (LEN(@text) - @index))<br />
END<br />
ELSE<br />
SET @text = RIGHT(@text, (LEN(@text) - @index))<br />
END<br />
RETURN<br />
END<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://sqlblog.de/blog/2009/04/t-sql-split-column-in-several-rows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.Net-Snippets</title>
		<link>http://sqlblog.de/blog/2007/11/net-snippets/</link>
		<comments>http://sqlblog.de/blog/2007/11/net-snippets/#comments</comments>
		<pubDate>Thu, 29 Nov 2007 15:11:25 +0000</pubDate>
		<dc:creator>Ralf</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[VBA]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://sqlblog.de/blog/index.php/2007/11/29/net-snippets/</guid>
		<description><![CDATA[Unter .Net-Snippets findet man recht gute Lösungen. Sollte man immer mal besuchen, wenn man vor einem Problemchen steht. Außerdem gibt...]]></description>
			<content:encoded><![CDATA[<p><a title="http://dotnet-snippets.de" href="http://dotnet-snippets.de"><img src="http://sqlblog.de/blog/wp-content/uploads/2007/11/net-snippets.jpg" alt=".Net-Snippets" /></a></p>
<p>Unter <a title="dotnet-snippets" href="http://dotnet-snippets.de">.Net-Snippets</a> findet man recht gute Lösungen. Sollte man immer mal besuchen, wenn man vor einem Problemchen steht.</p>
<p>Außerdem gibt es noch ein nettes <a title="http://dotnet-snippets.de/dns/ffplugin.aspx" href="http://dotnet-snippets.de/dns/ffplugin.aspx">Firefox-Search-Plugin</a> zur schnellen Suche.</p>
<p><img src="http://sqlblog.de/blog/wp-content/uploads/2007/11/net-snippets2.jpg" alt=".Net-Snippets" /></p>
]]></content:encoded>
			<wfw:commentRss>http://sqlblog.de/blog/2007/11/net-snippets/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
	</channel>
</rss>

