<?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>my code trip &#187; 1 Line Wonder</title>
	<atom:link href="http://mycodetrip.com/tag/one-line-code-script/feed/" rel="self" type="application/rss+xml" />
	<link>http://mycodetrip.com</link>
	<description>stories from the information technology highway</description>
	<lastBuildDate>Mon, 29 Nov 2010 19:58:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>T- Sql To Concatenate A Table Column’s Values Into A Csv String</title>
		<link>http://mycodetrip.com/2008/12/16/t-sql-to-concatenate-a-table-column-values-into-a-csv-string_160/</link>
		<comments>http://mycodetrip.com/2008/12/16/t-sql-to-concatenate-a-table-column-values-into-a-csv-string_160/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 19:33:11 +0000</pubDate>
		<dc:creator>Shiva</dc:creator>
				<category><![CDATA[Tips / HowTos]]></category>
		<category><![CDATA[1 Line Wonder]]></category>
		<category><![CDATA[Code Snippet]]></category>

		<guid isPermaLink="false">http://mycodetrip.com/?p=160</guid>
		<description><![CDATA[1 line T-Sql code snippet to concatenate a table column’s values into A csv string ]]></description>
			<content:encoded><![CDATA[<p>A 1 line script to concatenate all the values in a table&#8217;s column and output a single comma-separated value (CSV) string, using the all-powerful SQL Serve <strong>STUFF function</strong> (for removing the leading comma) with the <strong>FOR XML clause</strong>.</p>
<p>The code snippet below uses the <strong>Pubs</strong> sample database that comes free with <strong>MS SQL Server</strong>.</p>
<pre class="brush: sql">
USE Pubs
GO

SELECT STUFF((SELECT &#039;,&#039; + au_fname FROM Authors FOR XML PATH(&#039;&#039;)),1, 1, &#039;&#039;) AS Column2CSVString
</pre>
<p>The output of the code snippet is as follows.</p>
<pre class="brush: html">
Abraham,Reginald,Cheryl,Michel,Innes,Ann,Marjorie,Morningstar,Burt,Sheryl,Livia,Shiva,Charlene,Stearns,Heather,Michael,Sylvia,Albert,Anne,Meander,Dean,Dirk,Johnson,Akiko
</pre>
<p>To order the column values in <strong>ASC </strong>or <strong>DESC </strong>order, add the <strong>ORDER BY clause</strong> after the tablename as shown below.</p>
<pre class="brush: sql">
USE Pubs
GO

SELECT STUFF((SELECT &#039;,&#039; + au_fname FROM Authors ORDER BY 1 ASC FOR XML PATH(&#039;&#039;)),1, 1, &#039;&#039;) AS Column2CSVString
</pre>
<p>The output of the code snippet is as follows.</p>
<pre class="brush: html">
Abraham,Akiko,Albert,Ann,Anne,Burt,Charlene,Cheryl,Dean,Dirk,Heather,Innes,Johnson,Livia,Marjorie,Meander,Michael,Michel,Morningstar,Reginald,Sheryl,Shiva,Stearns,Sylvia
</pre>
<p>Finally, if you want to make this really generic and use dynamic SQL to pass in the column name and table name and delimiter, then let me know and I will post the code here.</p>
]]></content:encoded>
			<wfw:commentRss>http://mycodetrip.com/2008/12/16/t-sql-to-concatenate-a-table-column-values-into-a-csv-string_160/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Truncate All Tables In Database Using sp_MSforeachtable</title>
		<link>http://mycodetrip.com/2008/09/19/truncate-all-tables-in-sql-server-database-using-sp_msforeachtable_71/</link>
		<comments>http://mycodetrip.com/2008/09/19/truncate-all-tables-in-sql-server-database-using-sp_msforeachtable_71/#comments</comments>
		<pubDate>Fri, 19 Sep 2008 15:08:11 +0000</pubDate>
		<dc:creator>Shiva Manjunath</dc:creator>
				<category><![CDATA[Tips / HowTos]]></category>
		<category><![CDATA[1 Line Wonder]]></category>
		<category><![CDATA[Code Snippet]]></category>

		<guid isPermaLink="false">http://mycodetrip.com/?p=71</guid>
		<description><![CDATA[1 line script to truncate all tables in a database]]></description>
			<content:encoded><![CDATA[<p>1 line script to <strong>truncate </strong>(delete all rows without logging the transactions) all tables within a <strong>SQL Server</strong> database.</p>
<pre class="brush: sql">
exec sp_MSforeachtable &quot;truncate table ? PRINT&#039;? truncated &#039;&quot;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://mycodetrip.com/2008/09/19/truncate-all-tables-in-sql-server-database-using-sp_msforeachtable_71/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

