<?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/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>Carlos Ferreira</title>
	<atom:link href="http://carlosferreira.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://carlosferreira.com</link>
	<description>A blog based on Microsoft Technologies</description>
	<lastBuildDate>Wed, 04 Oct 2017 12:26:27 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.1</generator>
<site xmlns="com-wordpress:feed-additions:1">61359447</site>	<item>
		<title>How to install Keras and Theano in Anaconda Python on Windows</title>
		<link>http://carlosferreira.com/how-to-install-keras-and-theano-in-anaconda-python-on-windows/</link>
					<comments>http://carlosferreira.com/how-to-install-keras-and-theano-in-anaconda-python-on-windows/#comments</comments>
		
		<dc:creator><![CDATA[Carlos Ferreira]]></dc:creator>
		<pubDate>Sun, 03 Sep 2017 18:24:42 +0000</pubDate>
				<category><![CDATA[Data Science]]></category>
		<category><![CDATA[Deep Learning]]></category>
		<category><![CDATA[Keras]]></category>
		<category><![CDATA[Machine Learning]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Theano]]></category>
		<category><![CDATA[Anaconda]]></category>
		<guid isPermaLink="false">http://carlosferreira.com/?p=410</guid>

					<description><![CDATA[Provides instruction on how to install Theano Keras and Anaconda on a Windows 10 PC.]]></description>
										<content:encoded><![CDATA[<h1 class="main-headline">Install Anaconda</h1>
<p>Is the leading open data science platform and is the recommended tool for use with Theano.  It is a free, easy to install python distribution and package manager that has a collection of over 720 open source package.  You can find a cheat sheet at the following location: <a href="https://docs.continuum.io/_downloads/Anaconda_CheatSheet.pdf">Anaconda cheat sheet</a></p>
<ul>
<li>Install <a href="https://www.continuum.io/downloads">Anaconda</a> x64.</li>
<li>Open the Anaconda prompt</li>
</ul>
<p>Conda is the Anaconda command line for managing packages.  We will be using this to install all the python related packages required. Before doing this we must ensure we have the most up to date version of Conda.  To do this type the following in the Anaconda prompt:</p><pre class="crayon-plain-tag">conda update conda</pre><p></p>
<p class="comments-section">Next, we update Anaconda and all installed packages. To do this type the following in the Anaconda prompt:</p>
<p></p><pre class="crayon-plain-tag">&lt;/code&gt;conda update --all</pre><p>Next, we install the packages required for Theano. To do this type the following in the Anaconda prompt:</p><pre class="crayon-plain-tag">conda install numpy scipy mkl-service libpython mingw m2w64-toolchain nose sphinx git</pre><p></p>
<h1>Install Theano</h1>
<p>Theano is a Python library that allows you to define, optimize, and evaluate mathematical expressions involving multi-dimensional arrays efficiently. It can use GPUs and perform efficient symbolic differentiation.  To install the latest version of Theano type in the following in the Anaconda prompt:</p><pre class="crayon-plain-tag">pip install git+git://github.com/Theano/Theano.git</pre><p></p>
<h1>Install Keras</h1>
<p>Keras is a high-level deep learning library written in Python which runs on top of either  <a href="https://github.com/tensorflow/tensorflow">TensorFlow</a>, <a href="https://github.com/Microsoft/cntk">CNTK</a>, or <a href="https://github.com/Theano/Theano">Theano</a>.  It was developed so that developers can easily create convolutional and/or recurrent networks.  To install the latest version of Keras, type in the following in the Anaconda prompt:</p><pre class="crayon-plain-tag">pip install git+git://github.com/fchollet/keras.git</pre><p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>http://carlosferreira.com/how-to-install-keras-and-theano-in-anaconda-python-on-windows/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">410</post-id>	</item>
		<item>
		<title>Equivalent of Oracle PL/SQL TRIM function in SQL Server (T-SQL)</title>
		<link>http://carlosferreira.com/equivalent-of-oracle-plsql-trim-function-in-sql-server-t-sql/</link>
					<comments>http://carlosferreira.com/equivalent-of-oracle-plsql-trim-function-in-sql-server-t-sql/#respond</comments>
		
		<dc:creator><![CDATA[Carlos Ferreira]]></dc:creator>
		<pubDate>Thu, 30 Jan 2014 05:25:19 +0000</pubDate>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[LTRIM]]></category>
		<category><![CDATA[PL/SQL]]></category>
		<category><![CDATA[RTRIM]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[TRIM]]></category>
		<guid isPermaLink="false">http://carlosferreira.com/?p=338</guid>

					<description><![CDATA[Explains how to get the functionality of the TRIM function in Oracle's PL/SQL in SQL Server's T-SQL language.]]></description>
										<content:encoded><![CDATA[<p><span style="font-size: 14px; line-height: 1.5em;">In </span><strong style="font-size: 14px; line-height: 1.5em;">PL/SQL</strong><span style="font-size: 14px; line-height: 1.5em;">, when the </span><a style="font-size: 14px; line-height: 1.5em;" title="TRIM" href="http://docs.oracle.com/javadb/10.6.1.0/ref/rreftrimfunc.html">TRIM </a>function <span style="font-size: 14px; line-height: 1.5em;">is called with just the data parameter it will strip the leading and trailing spaces.   You can accomplish the same functionality in t-sql by using two t-sql functions:  <a title="LTRIM" href="http://technet.microsoft.com/en-us/library/ms177827.aspx">LTRIM </a>(strips leading spaces) and <a title="RTRIM" href="http://technet.microsoft.com/en-us/library/ms178660(v=sql.110).aspx">RTRIM </a>(strips trailing spaces).  An example of accomplishing this would be the following:</span></p><pre class="crayon-plain-tag">SELECT LTRIM(RTRIM('      hello world    '))</pre><p><span style="font-size: 14px; line-height: 1.5em;">One thing to note is that TRIM with the LEADING parameter and &#8216; &#8216; as the character to be trimmed is exactly the equivalent of the LTRIM function in t-sql;  TRIM with the TRAILING parameter and &#8216; &#8216; as the character to be trimmed is exactly the equivalent of the RTRIM function in t-sql.</span></p>
<p>You can also create a user defined function for TRIM in your database.  The following listing below will do that for you.</p><pre class="crayon-plain-tag">SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Carlos Ferreira
-- Create date: January 29 2014
-- Description:	TRIM function (similar to Oracle)
-- =============================================
CREATE FUNCTION Trim
(
		@string Varchar(Max)
)
RETURNS Varchar(Max)
AS
BEGIN
	-- Declare the return variable here
	DECLARE @stringTrimed Varchar(Max)

	SET @stringTrimed = ltrim(rtrim(@string))

	-- Return the result of the function
	RETURN @stringTrimed
END
GO</pre><p>After running the above script you could test it by running the following:</p><pre class="crayon-plain-tag">SELECT dbo.Trim(' test me ')</pre><p><strong>References</strong></p>
<p><a title="PL/SQL TRIM" href="http://docs.oracle.com/javadb/10.6.1.0/ref/rreftrimfunc.html"> PL/SQL TRIM</a></p>
<p><a title="LTRIM" href="http://technet.microsoft.com/en-us/library/ms177827.aspx">TSQL LTRIM</a></p>
<p><a title="RTRIM" href="http://technet.microsoft.com/en-us/library/ms178660(v=sql.110).aspx">TSQL RTRIM</a></p>
]]></content:encoded>
					
					<wfw:commentRss>http://carlosferreira.com/equivalent-of-oracle-plsql-trim-function-in-sql-server-t-sql/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">338</post-id>	</item>
		<item>
		<title>Writing CSV files using CSVHelper package (C#, IEnumerable)</title>
		<link>http://carlosferreira.com/writing-csv-files-using-csvhelper-package-c-ienumerable/</link>
					<comments>http://carlosferreira.com/writing-csv-files-using-csvhelper-package-c-ienumerable/#comments</comments>
		
		<dc:creator><![CDATA[Carlos Ferreira]]></dc:creator>
		<pubDate>Thu, 09 Jan 2014 03:35:14 +0000</pubDate>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[CSV]]></category>
		<category><![CDATA[CSVHelper]]></category>
		<category><![CDATA[IEnumerable]]></category>
		<category><![CDATA[writing]]></category>
		<guid isPermaLink="false">http://carlosferreira.com/?p=320</guid>

					<description><![CDATA[This is a follow-up on my post on how to read a CSV file using&#160;Josh Close’s CsvHelper. &#160;CsvHelper is a fast and flexible .NET&#160;library for reading and writing CSV files. Below I will now show how to write CSV files using&#160;CsvHelper. &#160;The example will actually be reading a CSV file and then writing the contents [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>This is a follow-up on my <a title="Reading CSV files using CSVHelper package (C#, IEnumerable)" href="http://carlosferreira.com/reading-csv-files-using-csvhelper-package-c-ienumerable/">post </a>on how to read a <strong><a title="CSV" href="http://en.wikipedia.org/wiki/Comma-separated_values" target="_blank">CSV </a></strong>file using&nbsp;Josh Close’s <a title="CSVHelper" href="https://github.com/JoshClose/CsvHelper" target="_blank"><strong>CsvHelper</strong></a>. &nbsp;CsvHelper is a fast and flexible .NET&nbsp;library for reading and writing CSV files.</p>
<p>Below I will now show how to <strong>write</strong> CSV files using&nbsp;CsvHelper. &nbsp;The example will actually be reading a CSV file and then writing the contents of that CSV into another but doing it <strong>three</strong> times. &nbsp;Each time we do this we will use another method (<strong>WriteRecords</strong> for all records at once, <strong>WriteRecord</strong> for writing one record, and <strong>WriteField</strong> for writing one field).</p>
<p>Our sample input CSV file will look like the following.</p>
<p>CommonName,FormalName,TelephoneCode,CountryCode</p>
<p>Argentina,Argentine Republic,54,ARG<br />
Armenia,Republic of Armenia,374,ARM<br />
Australia,Commonwealth of Australia,61,AUS<br />
Austria,Republic of Austria,43,AUT<br />
&#8220;Bahamas, The&#8221;,Commonwealth of The Bahamas,-241,BHS<br />
Bangladesh,People&#8217;s Republic of Bangladesh,880,BGD</p>
<p>Note this CSV file is a simpler file based on the file which is located&nbsp;<a href="http://www.andrewpatton.com/countrylist.html">here</a>.</p>
<p>The first thing to do is to Install CsvHelper. &nbsp;To do this run the&nbsp;following command in the Package Manager Console:</p><pre class="crayon-plain-tag">Install-Package CsvHelper</pre><p>Now add CsvHelper to the program by adding:</p><pre class="crayon-plain-tag">using CsvHelper;</pre><p>The next step is to create a class which has properties with the same name of the column headings found in the csv file. &nbsp;Below you will find an example of a class which does this:</p><pre class="crayon-plain-tag">class DataRecord
    {
        //Should have properties which correspond to the Column Names in the file
        //i.e. CommonName,FormalName,TelephoneCode,CountryCode
        public String CommonName { get; set; }
        public String FormalName { get; set; }
        public String TelephoneCode { get; set; }
        public String CountryCode { get; set; }
    }</pre><p><span style="font-size: 14px; line-height: 1.5em;">Finally create an instance of CSVReader and CSVWriter &nbsp;and invoke the GetRecords method using the DataRecord class to read the CSV file.&nbsp;</span></p><pre class="crayon-plain-tag">var reader = new CsvReader(sr); 
var writer = new CsvWriter(sw);

IEnumerable records = reader.GetRecords&lt;DataRecord&gt;().ToList();</pre><p>Once we have the completed we are now ready to write the file out. &nbsp;We first will write the entire file out by using the WriteRecords method. &nbsp;Note this method will also normally write the header out automatically.</p><pre class="crayon-plain-tag">writer.WriteRecords(records);</pre><p>We then write the records out again but this time we will do so by iterating thru the records collection and writing the entire record using the <strong>WriteRecord</strong> method and also by writing the fields of the record using the <strong>WriteField</strong> method.</p><pre class="crayon-plain-tag">foreach (DataRecord record in records)
                    { 
                       //Write entire current record
                       writer.WriteRecord(record);

                       //write record field by field
                       writer.WriteField(record.CommonName);
                       writer.WriteField(record.FormalName);
                       writer.WriteField(record.TelephoneCode);
                       writer.WriteField(record.CountryCode);
                       //ensure you write end of record when you are using WriteField method
                       writer.NextRecord();
                    }</pre><p>One point to note that if you were writing a file using the WriteRecord or WriteField methods, you will not get a header record in the file. &nbsp; If you wish to have a header record us the <strong>WriteHeader</strong> method (example is commented out in final code).</p>
<p>A completed example can be found below:</p><pre class="crayon-plain-tag">using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CsvHelper;

namespace CSVHelperWriteSample
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var sr = new StreamReader(@&quot;countrylist.csv&quot;))
            {
                using (var sw = new StreamWriter(@&quot;countrylistoutput.csv&quot;))
                {
                    var reader = new CsvReader(sr); 
                    var writer = new CsvWriter(sw);

                    //CSVReader will now read the whole file into an enumerable
                    IEnumerable records = reader.GetRecords&lt;DataRecord&gt;().ToList();

                    //Write the entire contents of the CSV file into another
                    writer.WriteRecords(records);

                    //Now we will write the data into the same output file but will do it 
                    //Using two methods.  The first is writing the entire record.  The second
                    //method writes individual fields.  Note you must call NextRecord method after 
                    //using Writefield to terminate the record.

                    //Note that WriteRecords will write a header record for you automatically.  If you 
                    //are not using the WriteRecords method and you want to a header, you must call the 
                    //Writeheader method like the following:
                    //
                    //writer.WriteHeader&lt;DataRecord&gt;();
                    //
                    //Do not use WriteHeader as WriteRecords will have done that already.

                    foreach (DataRecord record in records)
                    { 
                       //Write entire current record
                       writer.WriteRecord(record);

                       //write record field by field
                       writer.WriteField(record.CommonName);
                       writer.WriteField(record.FormalName);
                       writer.WriteField(record.TelephoneCode);
                       writer.WriteField(record.CountryCode);
                       //ensure you write end of record when you are using WriteField method
                       writer.NextRecord();
                    }
                }
            }
        }
    }
}</pre><p>&nbsp;</p>
<p>You can download this sample code with CsvHelper and CSV file <a href="http://carlosferreira.com/wp-content/uploads/2014/01/CSVHelperWriteSample.zip">here</a>:</p>
]]></content:encoded>
					
					<wfw:commentRss>http://carlosferreira.com/writing-csv-files-using-csvhelper-package-c-ienumerable/feed/</wfw:commentRss>
			<slash:comments>19</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">320</post-id>	</item>
		<item>
		<title>Insert data into new (or existing table) from another (T-SQL, PL/SQL, SQL Server, Oracle)</title>
		<link>http://carlosferreira.com/insert-data-into-new-or-existing-table-from-another-t-sql-plsql-sql-server-oracle/</link>
					<comments>http://carlosferreira.com/insert-data-into-new-or-existing-table-from-another-t-sql-plsql-sql-server-oracle/#comments</comments>
		
		<dc:creator><![CDATA[Carlos Ferreira]]></dc:creator>
		<pubDate>Tue, 24 Dec 2013 02:44:59 +0000</pubDate>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Copy]]></category>
		<category><![CDATA[Data]]></category>
		<category><![CDATA[PL/SQL]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Table]]></category>
		<guid isPermaLink="false">http://carlosferreira.com/?p=285</guid>

					<description><![CDATA[Often times we wish to copy data from one table into another.  The methods of doing this where the new table does not exist will be slightly different from the case in which it does exist.  Also I will show display the method of doing this in T-SQL and PL/SQL (just because I get confused [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Often times we wish to copy data from one table into another.  The methods of doing this where the new table does not exist will be slightly different from the case in which it does exist.  Also I will show display the method of doing this in T-SQL and PL/SQL (just because I get confused all the time when I switch databases <img decoding="async" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="https://i0.wp.com/carlosferreira.com/wp-content/uploads/2013/12/wlEmoticon-smile.png" data-recalc-dims="1" /> ).</p>
<h3>SQL copy tables to new table</h3>
<p>When performing this command, a table will created using the same data types as the columns which as selected in the select statement.  This is usually very useful when making a copy of the existing table before making any alterations to the data.</p>
<h4>T-SQL:</h4>
<p></p><pre class="crayon-plain-tag">SELECT * 
INTO Sales.CustomerBackup 
FROM Sales.Customer;</pre><p></p>
<h4>PL/SQL:</h4>
<p></p><pre class="crayon-plain-tag">CREATE TABLE CustomerBackup 
AS 
SELECT * FROM Customer;</pre><p>&nbsp;</p>
<h3>SQL copy tables to existing table</h3>
<p>These following when executed will insert data into already existing table.  It will match fields based on name if you choose to list the fields in the select clause.  This normally useful for when you need to reinsert data (don&#8217;t ask why&#8230; <img decoding="async" alt="Smile" src="https://i0.wp.com/carlosferreira.com/wp-content/uploads/2013/12/wlEmoticon-smile.png" data-recalc-dims="1" />)</p>
<h4>T-SQL:</h4>
<p></p><pre class="crayon-plain-tag">INSERT INTO Sales.CustomerBackup (PersonID, StoreID, ModifiedDate, AccountNumber, rowguid)  
SELECT PersonID, StoreID, ModifiedDate, AccountNumber, rowguid FROM Sales.Customer;</pre><p></p>
<h4>PL/SQL:</h4>
<p></p><pre class="crayon-plain-tag">INSERT INTO CustomerBackup 
SELECT * FROM Customer;</pre><p></p>
]]></content:encoded>
					
					<wfw:commentRss>http://carlosferreira.com/insert-data-into-new-or-existing-table-from-another-t-sql-plsql-sql-server-oracle/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">285</post-id>	</item>
		<item>
		<title>How to combine values from multiple rows of a single column (T-SQL, Microsoft SQL Server, FOR XML PATH, CSV ).</title>
		<link>http://carlosferreira.com/how-to-combine-values-from-multiple-rows-of-a-single-column-t-sql-microsoft-sql-server-for-xml-path-csv/</link>
					<comments>http://carlosferreira.com/how-to-combine-values-from-multiple-rows-of-a-single-column-t-sql-microsoft-sql-server-for-xml-path-csv/#comments</comments>
		
		<dc:creator><![CDATA[Carlos Ferreira]]></dc:creator>
		<pubDate>Thu, 19 Dec 2013 03:36:17 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">http://carlosferreira.com/?p=281</guid>

					<description><![CDATA[The Problem: I need a way to roll-up multiple rows into one row and one column.  In essence I needed to convert something that looked like this: [crayon-69dc64a43b433188658303/] Into something that looks like this: The Solution: The solution I will show will make use of the FOR XML PATH clause and STUFF commands in T-SQL. FOR XML PATH [&#8230;]]]></description>
										<content:encoded><![CDATA[<h2><strong>The Problem:</strong></h2>
<p>I need a way to <span style="text-decoration: underline;">roll-up multiple rows into one row and one column</span>.  In essence I needed to convert something that looked like this:</p>
<p><div id="attachment_295" style="width: 254px" class="wp-caption alignnone"><a href="https://i0.wp.com/carlosferreira.com/wp-content/uploads/2014/01/image_thumb.png"><img aria-describedby="caption-attachment-295" decoding="async" loading="lazy" class="size-full wp-image-295" alt="Original SubCategories Lisitng" src="https://i0.wp.com/carlosferreira.com/wp-content/uploads/2014/01/image_thumb.png?resize=244%2C217" width="244" height="217" data-recalc-dims="1" /></a><p id="caption-attachment-295" class="wp-caption-text">Original SubCategories Listing</p></div><br />
<pre class="crayon-plain-tag">USE AdventureWorks2012; 
GO 
SELECT C.Name, 
       SC.Name 
FROM   [Production].[ProductCategory] C 
       LEFT JOIN [Production].[ProductSubcategory] SC 
              ON C.ProductCategoryID = SC.ProductCategoryID;</pre><br />
Into something that looks like this:</p>
<div id="attachment_297" style="width: 254px" class="wp-caption alignnone"><a href="https://i0.wp.com/carlosferreira.com/wp-content/uploads/2014/01/image_thumb1.png"><img aria-describedby="caption-attachment-297" decoding="async" loading="lazy" class="size-full wp-image-297" alt="SubCategories formatted data" src="https://i0.wp.com/carlosferreira.com/wp-content/uploads/2014/01/image_thumb1.png?resize=244%2C67" width="244" height="67" data-recalc-dims="1" /></a><p id="caption-attachment-297" class="wp-caption-text">SubCategories formatted data</p></div>
<h2><strong>The Solution:</strong></h2>
<p>The solution I will show will make use of the <strong><a title="FOR XML PATH clause" href="http://technet.microsoft.com/en-us/library/ms178107.aspx" target="_blank">FOR XML PATH</a></strong> clause and <strong><a href="http://msdn.microsoft.com/pt-br/library/ms188043.aspx">STUFF</a></strong> commands in T-SQL.</p>
<h3>FOR XML PATH Clause</h3>
<p>Will will make use of the XML functionality of SQL Server to amalgamate the series of rows into one row.  In order to create a XML string you must append the FOR XML command after any regular query.   There are four options to append to the <strong>FOR XML PATH</strong> command which will alter what the result will look like.  These options are either RAW, AUTO, EXPLICIT, or PATH.  For this solution we will use the PATH option (will explain these four option in more detail in a later post).</p>
<p>The following query shows a regular query which retrieves the subcategory name in an XML string</p><pre class="crayon-plain-tag">SELECT Name from [Production].[ProductSubcategory] FOR XML PATH('');</pre><p>The results look like the following:</p>
<p><a href="https://i0.wp.com/carlosferreira.com/wp-content/uploads/2013/12/XMLResult1.png"><img decoding="async" loading="lazy" class="alignnone size-medium wp-image-304" alt="XMLResult" src="https://i0.wp.com/carlosferreira.com/wp-content/uploads/2013/12/XMLResult1.png?resize=300%2C46" width="300" height="46" srcset="https://i0.wp.com/carlosferreira.com/wp-content/uploads/2013/12/XMLResult1.png?resize=300%2C46 300w, https://i0.wp.com/carlosferreira.com/wp-content/uploads/2013/12/XMLResult1.png?w=720 720w" sizes="(max-width: 300px) 100vw, 300px" data-recalc-dims="1" /></a></p>
<dl class="wp-caption alignnone" id="attachment_313" style="width: 310px;">
<dt class="wp-caption-dt"></dt>
</dl>
<p> You will notice that you get a formatted XML string without a root node.  <span style="text-decoration: underline;">To convert this list to a <a title="CSV" href="http://en.wikipedia.org/wiki/Comma-separated_values" target="_blank">CSV</a> string we just need to append a comma (&#8220;,&#8221;)  to the name field</span>.</p>
<p>The following sql query demonstrates the XML string being converted to a CSV string:</p><pre class="crayon-plain-tag">SELECT ',' + Name from [Production].[ProductSubcategory] FOR XML PATH('');</pre><p><div id="attachment_313" style="width: 310px" class="wp-caption alignnone"><a href="https://i0.wp.com/carlosferreira.com/wp-content/uploads/2013/12/CSV_Result.png"><img aria-describedby="caption-attachment-313" decoding="async" loading="lazy" class="size-medium wp-image-313" alt="CSV Result" src="https://i0.wp.com/carlosferreira.com/wp-content/uploads/2013/12/CSV_Result.png?resize=300%2C59" width="300" height="59" srcset="https://i0.wp.com/carlosferreira.com/wp-content/uploads/2013/12/CSV_Result.png?resize=300%2C59 300w, https://i0.wp.com/carlosferreira.com/wp-content/uploads/2013/12/CSV_Result.png?w=304 304w" sizes="(max-width: 300px) 100vw, 300px" data-recalc-dims="1" /></a><p id="caption-attachment-313" class="wp-caption-text">CSV Result</p></div></p>
<p>This is getting a bit closer to the results we want, but we if you haven&#8217;t noticed the string begins with a comma which we should remove.  In order to do this we will use the t-sql <strong><a href="http://msdn.microsoft.com/pt-br/library/ms188043.aspx">STUFF</a></strong> function</p>
<h3>STUFF() Function</h3>
<p>The syntax of the t-sql STUFF function looks like the following:</p><pre class="crayon-plain-tag">STUFF (&nbsp;character_expression , start , length , replaceWith_expression )</pre><p></p>
<h5>To remove the first character of the string all we need to so is do something like the following:</h5>
<p></p><pre class="crayon-plain-tag">Stuff( result of the query listed above, 1, 1, '')</pre><p>This says, starting with the first <code>1</code> character place, replace 1 characters with nothing <code>''.</code></p>
<h3>What does the final solution look like?</h3>
<p></p><pre class="crayon-plain-tag">USE AdventureWorks2012
GO
SELECT CAT.Name AS [Category],
	   SubCatName =
            STUFF((    SELECT ','+ SUB.Name AS [text()]
                        FROM Production.ProductSubcategory SUB
                        WHERE
                        SUB.ProductCategoryID = CAT.ProductCategoryID
                        FOR XML PATH('') 
                        ), 1, 1,'')
FROM  Production.ProductCategory CAT;</pre><p></p>
<div>
<dl>
<dt><a href="https://i0.wp.com/carlosferreira.com/wp-content/uploads/2014/01/image_thumb1.png"><img decoding="async" loading="lazy" alt="SubCategories formatted data" src="https://i0.wp.com/carlosferreira.com/wp-content/uploads/2014/01/image_thumb1.png?resize=244%2C67" width="244" height="67" data-recalc-dims="1" /></a></dt>
<dd>SubCategories formatted data</dd>
</dl>
<h3> <span style="font-size: 1.17em; line-height: 1.5em;">References</span></h3>
</div>
<ul>
<li>
<ul>
<li><a href="http://msdn.microsoft.com/pt-br/library/ms188043.aspx">STUFF (Transact-SQL)</a></li>
<li><a href="http://msdn.microsoft.com/pt-br/library/ms178107.aspx">FOR XML (SQL SERVER)</a></li>
<li><a title="CSV" href="http://en.wikipedia.org/wiki/Comma-separated_values" target="_blank">CSV</a></li>
</ul>
</li>
</ul>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>http://carlosferreira.com/how-to-combine-values-from-multiple-rows-of-a-single-column-t-sql-microsoft-sql-server-for-xml-path-csv/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">281</post-id>	</item>
		<item>
		<title>Run Transact-SQL Script Files  Using sqlcmd&#8211;SQL Server T-SQL</title>
		<link>http://carlosferreira.com/run-transact-sql-script-files-using-sqlcmdsql-server-t-sql/</link>
					<comments>http://carlosferreira.com/run-transact-sql-script-files-using-sqlcmdsql-server-t-sql/#respond</comments>
		
		<dc:creator><![CDATA[Carlos Ferreira]]></dc:creator>
		<pubDate>Sun, 15 Dec 2013 22:52:38 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[Load]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[SQLCMD]]></category>
		<category><![CDATA[T-SQL]]></category>
		<guid isPermaLink="false">http://carlosferreira.com/?p=276</guid>

					<description><![CDATA[Problem: I recently received a script which creates a database and loads data.  I was unfortunately too large for SQL Server Management Studio to process. Solution: You can use the sqlcmd utility to run the script file. The example below shows the execution of a script file called script.sql which is located on the C [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Problem:</p>
<p>I recently received a script which creates a database and loads data.  I was unfortunately too large for SQL Server Management Studio to process.</p>
<p>Solution:</p>
<p>You can use the <a href="http://technet.microsoft.com/en-us/library/ms162773.aspx">sqlcmd</a> utility to run the script file. The example below shows the execution of a script file called script.sql which is located on the C drive and a connection is made to the SQL Server using integrated security.</p>
<p>To run the script file</p>
<ol>
<li>Open a windows command prompt window.</li>
<li>In the command prompt window, type: sqlcmd –S SQLServerName-i C:\DatabaseLoad.sql</li>
<li>Press ENTER.</li>
</ol>
]]></content:encoded>
					
					<wfw:commentRss>http://carlosferreira.com/run-transact-sql-script-files-using-sqlcmdsql-server-t-sql/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">276</post-id>	</item>
		<item>
		<title>How to delete duplicate records from your SQL Server tables &#8211; T-SQL</title>
		<link>http://carlosferreira.com/how-to-delete-duplicate-records-from-your-sql-server-tables/</link>
					<comments>http://carlosferreira.com/how-to-delete-duplicate-records-from-your-sql-server-tables/#respond</comments>
		
		<dc:creator><![CDATA[Carlos Ferreira]]></dc:creator>
		<pubDate>Thu, 12 Dec 2013 04:18:06 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Common Table Expression]]></category>
		<category><![CDATA[CTE]]></category>
		<category><![CDATA[distinct]]></category>
		<category><![CDATA[duplicates]]></category>
		<category><![CDATA[remove]]></category>
		<category><![CDATA[row_number]]></category>
		<category><![CDATA[SQL Server 2000]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<guid isPermaLink="false">http://carlosferreira.com/?p=250</guid>

					<description><![CDATA[Below you will find two methods that can be used to remove duplicate records from you Microsoft SQL Server tables. Method 1: This method will only work in SQL Server 2005 and later; if you need to remove duplicates from an earlier version please upgrade you SQL Server version.  Just kidding!  Use the technique in [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Below you will find two methods that can be used to remove duplicate records from you Microsoft SQL Server tables.</p>
<p><strong>Method 1:</strong></p>
<p>This method will only work in SQL Server 2005 and later; if you need to remove duplicates from an earlier version please upgrade you SQL Server version.  Just kidding!  Use the technique in method 2.  Actually you really should upgrade your version of SQL Server&#8230;</p>
<p>This method uses the Common Table Expression functionality and row_number function which was introduced in Microsoft SQL Server 2005.   The key strategy to this method is to generate a number next to the  records which denotes the row number.</p>
<p>So in essence we want to transform this:</p>
<div id="attachment_267" style="width: 175px" class="wp-caption alignnone"><a href="https://i0.wp.com/carlosferreira.com/wp-content/uploads/2013/12/DuplicatedResult.png"><img aria-describedby="caption-attachment-267" decoding="async" loading="lazy" class="size-full wp-image-267" alt="Duplicated Records" src="https://i0.wp.com/carlosferreira.com/wp-content/uploads/2013/12/DuplicatedResult.png?resize=165%2C197" width="165" height="197" data-recalc-dims="1" /></a><p id="caption-attachment-267" class="wp-caption-text">Duplicated Records</p></div>
<p>To this:</p>
<div id="attachment_268" style="width: 195px" class="wp-caption alignnone"><a href="https://i0.wp.com/carlosferreira.com/wp-content/uploads/2013/12/DuplicatedResultWithNumber.png"><img aria-describedby="caption-attachment-268" decoding="async" loading="lazy" class=" wp-image-268" title="Duplicated Results with Numbers" alt="DuplicatedResultWithNumber" src="https://i0.wp.com/carlosferreira.com/wp-content/uploads/2013/12/DuplicatedResultWithNumber.png?resize=185%2C164" width="185" height="164" data-recalc-dims="1" /></a><p id="caption-attachment-268" class="wp-caption-text">Duplicated Results with Numbers</p></div>
<p>And remove all instances of those rows which the row number column do not correspond to 1.</p>
<p>Below is a script which can be used to demonstrate this.   Also you can use this <a title="sql fiddle link" href="http://www.sqlfiddle.com/#!6/95beb/5" target="_blank">link </a>in SQL Fiddle.</p><pre class="crayon-plain-tag">-- Create Table
CREATE TABLE PhoneticAlphabet (Alphabet char(1),  CodeWord varchar(20))

-- Load Sample Data in Table
INSERT INTO  PhoneticAlphabet VALUES ('A', 'Alfa')
INSERT INTO  PhoneticAlphabet VALUES ('B', 'Brave')
INSERT INTO  PhoneticAlphabet VALUES ('C', 'Charlie')
INSERT INTO  PhoneticAlphabet VALUES ('D', 'Delta')
INSERT INTO  PhoneticAlphabet VALUES ('E', 'Echo')
INSERT INTO  PhoneticAlphabet VALUES ('F', 'Foxtrot')
INSERT INTO  PhoneticAlphabet VALUES ('G', 'Gulf')
INSERT INTO  PhoneticAlphabet VALUES ('H', 'Hotel')
INSERT INTO  PhoneticAlphabet VALUES ('I', 'India')
INSERT INTO  PhoneticAlphabet VALUES ('J', 'Juliett')
INSERT INTO  PhoneticAlphabet VALUES ('A', 'Alfa')
INSERT INTO  PhoneticAlphabet VALUES ('B', 'Brave')
INSERT INTO  PhoneticAlphabet VALUES ('C', 'Charlie')
INSERT INTO  PhoneticAlphabet VALUES ('D', 'Delta')
INSERT INTO  PhoneticAlphabet VALUES ('E', 'Echo')
INSERT INTO  PhoneticAlphabet VALUES ('F', 'Foxtrot')
INSERT INTO  PhoneticAlphabet VALUES ('G', 'Gulf')
INSERT INTO  PhoneticAlphabet VALUES ('H', 'Hotel')
INSERT INTO  PhoneticAlphabet VALUES ('I', 'India')
INSERT INTO  PhoneticAlphabet VALUES ('J', 'Juliett')

--See table before deletion
SELECT * FROM PhoneticAlphabet ORDER BY Alphabet;

--Display what the table will look like when we sort it by Alphabet and CodeWord
--and use the row_number function over the dataset see http://technet.microsoft.com/en-us/library/ms186734.aspx
--for infromation of row_number function.
SELECT
  Alphabet
  , CodeWord
  , row_number() over (partition by Alphabet, CodeWord order by Alphabet) as rn
FROM PhoneticAlphabet;

--Create a Common Table Expression and delete all rows which value greater than 1
WITH PhoneticAlphabetWithRows AS (
SELECT
  Alphabet
  , CodeWord
  , row_number() over (partition by Alphabet, CodeWord order by Alphabet) as rn
FROM PhoneticAlphabet
)
DELETE PhoneticAlphabetWithRows where rn &amp;gt; 1;

--See the table after deletion
select * from PhoneticAlphabet ORDER BY Alphabet;</pre><p><strong>Method 2:</strong></p>
<p>This method should work on all versions for SQL Server.  It basically works by copying the unique rows out of the original table into a temporary table, and then deleting all records from the original table;  the unique rows from the temporary table are then copied into the original table.</p>
<p>Link to SQL Fiddle is <a href="http://www.sqlfiddle.com/#!6/163d9/1" target="_blank">here</a>.</p>
<p><span style="font-family: Consolas, Monaco, monospace; font-size: 12px; line-height: 18px;">&#8212; Create Table</span></p><pre class="crayon-plain-tag">CREATE TABLE PhoneticAlphabet (Alphabet char(1),  CodeWord varchar(20))

-- Load Sample Data in Table
INSERT INTO  PhoneticAlphabet VALUES ('A', 'Alfa')
INSERT INTO  PhoneticAlphabet VALUES ('B', 'Brave')
INSERT INTO  PhoneticAlphabet VALUES ('C', 'Charlie')
INSERT INTO  PhoneticAlphabet VALUES ('D', 'Delta')
INSERT INTO  PhoneticAlphabet VALUES ('E', 'Echo')
INSERT INTO  PhoneticAlphabet VALUES ('F', 'Foxtrot')
INSERT INTO  PhoneticAlphabet VALUES ('G', 'Gulf')
INSERT INTO  PhoneticAlphabet VALUES ('H', 'Hotel')
INSERT INTO  PhoneticAlphabet VALUES ('I', 'India')
INSERT INTO  PhoneticAlphabet VALUES ('J', 'Juliett')
INSERT INTO  PhoneticAlphabet VALUES ('A', 'Alfa')
INSERT INTO  PhoneticAlphabet VALUES ('B', 'Brave')
INSERT INTO  PhoneticAlphabet VALUES ('C', 'Charlie')
INSERT INTO  PhoneticAlphabet VALUES ('D', 'Delta')
INSERT INTO  PhoneticAlphabet VALUES ('E', 'Echo')
INSERT INTO  PhoneticAlphabet VALUES ('F', 'Foxtrot')
INSERT INTO  PhoneticAlphabet VALUES ('G', 'Gulf')
INSERT INTO  PhoneticAlphabet VALUES ('H', 'Hotel')
INSERT INTO  PhoneticAlphabet VALUES ('I', 'India')
INSERT INTO  PhoneticAlphabet VALUES ('J', 'Juliett')

--Lets see the duplicated records
SELECT * FROM PhoneticAlphabet;

--Insert the distinct rows from the duplicate rows table to a new temporary table.
SELECT DISTINCT * INTO #tmp FROM [PhoneticAlphabet];

--Delete all the rows from the original table
DELETE FROM PhoneticAlphabet;

--Copy the distinct rows from the temporary table back into the original table (which was empty).

INSERT INTO PhoneticAlphabet
SELECT * FROM #tmp; 

DROP TABLE #tmp;

--Lets now see the table without duplicates
SELECT * FROM PhoneticAlphabet;</pre><p></p>
]]></content:encoded>
					
					<wfw:commentRss>http://carlosferreira.com/how-to-delete-duplicate-records-from-your-sql-server-tables/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">250</post-id>	</item>
		<item>
		<title>How to create a blocking transaction  in SQL Server &#8211; T-SQL (exclusive lock)</title>
		<link>http://carlosferreira.com/how-to-create-a-blocking-transaction-in-sql-server-t-sql-exclusive-lock/</link>
					<comments>http://carlosferreira.com/how-to-create-a-blocking-transaction-in-sql-server-t-sql-exclusive-lock/#comments</comments>
		
		<dc:creator><![CDATA[Carlos Ferreira]]></dc:creator>
		<pubDate>Tue, 10 Dec 2013 02:05:14 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Block]]></category>
		<category><![CDATA[Lock]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Transaction]]></category>
		<category><![CDATA[Waitfor]]></category>
		<guid isPermaLink="false">http://carlosferreira.com/?p=259</guid>

					<description><![CDATA[Excuse the odd topic.   I often like to experiment with SQL Server and create odd situations which we normally should be avoiding.  One of those things is creating SQL Statement which get blocked and creating a timeout.  One of the simplest ways to run a query against a table which is locked in another [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Excuse the odd topic.   I often like to experiment with SQL Server and create odd situations which we normally should be avoiding.  One of those things is creating SQL Statement which get blocked and creating a timeout.  One of the simplest ways to run a query against a table which is locked in another in another session.  To do this do the following:</p>
<p><span style="font-size: 13px; line-height: 19px;">1) Create a lock on a table.  </span></p>
<p>The example below demonstrates a lock on the Person table in the AdventureWorks2012 sample table.    The key points which make this work is to create a transaction, and then issuing a query using the TABLOCKX and HOLDLOCK table lock hints.  This will force an exclusive lock on the table.  To keep the lock for significant amount of time we specify that the transaction stays alive for a minute by introducing the WAITFOR DELAY &#8217;00:01:00&#8242; command, which will prevent any further execution of statements until a minute has passed.</p><pre class="crayon-plain-tag">USE AdventureWorks2012;
GO
BEGIN TRANSACTION
SELECT * FROM Person.Person WITH (TABLOCKX, HOLDLOCK);
WAITFOR DELAY '00:01:00' ---Wait a minute!
ROLLBACK TRANSACTION
--Release the lock</pre><p>2)  Now open up another session in SQL Server (new query from Microsoft SQL Server Management Studio), and execute the following query:</p><pre class="crayon-plain-tag">USE AdventureWorks2012;
GO
SELECT * FROM Person.Person;</pre><p>You will notice that after this query is excuted, the query seems to run forever.  It will actually never  execute until the query in step 1 is finished.</p>
<p>3) Check for blocked transaction.  You can find this by opening up an new query in Microsoft SQL Server Management Studio and executing the following query:</p><pre class="crayon-plain-tag">USE [master]
GO
SELECT  session_id
 ,db_name(database_id) as 'Database_Name'
 ,sql_text.text as 'SQL_Blocked'
 ,blocking_session_id
 ,wait_time
 ,wait_type
 ,last_wait_type
 ,wait_resource
 ,transaction_isolation_level
 ,lock_timeout
FROM sys.dm_exec_requests
CROSS APPLY sys.dm_exec_sql_text(sql_handle) as sql_text
WHERE blocking_session_id != 0</pre><p>I will explain in more detail how this blocking query works in a later post.</p>
<p><span style="font-size: 13px; line-height: 19px;">If you have any other tips on how to create a blocked transaction please share them in the comments below.</span></p>
]]></content:encoded>
					
					<wfw:commentRss>http://carlosferreira.com/how-to-create-a-blocking-transaction-in-sql-server-t-sql-exclusive-lock/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">259</post-id>	</item>
		<item>
		<title>About Me</title>
		<link>http://carlosferreira.com/about-me/</link>
					<comments>http://carlosferreira.com/about-me/#respond</comments>
		
		<dc:creator><![CDATA[Carlos Ferreira]]></dc:creator>
		<pubDate>Mon, 09 Dec 2013 03:08:53 +0000</pubDate>
				<category><![CDATA[Carlos]]></category>
		<category><![CDATA[about]]></category>
		<category><![CDATA[Carlos Ferreira]]></category>
		<category><![CDATA[Project Manager]]></category>
		<category><![CDATA[Techie]]></category>
		<guid isPermaLink="false">http://carlosferreira.com/?p=257</guid>

					<description><![CDATA[]]></description>
										<content:encoded><![CDATA[[contact-form]
]]></content:encoded>
					
					<wfw:commentRss>http://carlosferreira.com/about-me/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">257</post-id>	</item>
		<item>
		<title>Reading CSV files using CSVHelper package (C#, IEnumerable)</title>
		<link>http://carlosferreira.com/reading-csv-files-using-csvhelper-package-c-ienumerable/</link>
					<comments>http://carlosferreira.com/reading-csv-files-using-csvhelper-package-c-ienumerable/#comments</comments>
		
		<dc:creator><![CDATA[Carlos Ferreira]]></dc:creator>
		<pubDate>Fri, 29 Nov 2013 03:58:02 +0000</pubDate>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[CSV C# CSVHelper Linq IEnumerable]]></category>
		<guid isPermaLink="false">http://carlosferreira.com/?p=226</guid>

					<description><![CDATA[I have come across many times the need to incorporate the reading of CSV files in an application.  Below I will show how to use Josh Close’s CsvHelper to  import a CSV file which looks like the following (file will be included below). CommonName,FormalName,TelephoneCode,CountryCode Argentina,Argentine Republic,54,ARG Armenia,Republic of Armenia,374,ARM Australia,Commonwealth of Australia,61,AUS Austria,Republic of Austria,43,AUT [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>I have come across many times the need to incorporate the <em>reading of CSV</em> files in an application.  Below I will show how to use Josh Close’s <em><strong><a href="http://csvhelper.com">CsvHelper</a></strong></em> to  import a CSV file which looks like the following (file will be included below).</p>
<p>CommonName,FormalName,TelephoneCode,CountryCode<br />
Argentina,Argentine Republic,54,ARG<br />
Armenia,Republic of Armenia,374,ARM<br />
Australia,Commonwealth of Australia,61,AUS<br />
Austria,Republic of Austria,43,AUT<br />
&#8220;Bahamas, The&#8221;,Commonwealth of The Bahamas,-241,BHS<br />
Bangladesh,People&#8217;s Republic of Bangladesh,880,BGD</p>
<p><span style="line-height: 19px; font-size: 13px;">Note this CSV file is a simpler file based on the file which is located </span><a style="line-height: 19px; font-size: 13px;" href="http://www.andrewpatton.com/countrylist.html">here</a><span style="line-height: 19px; font-size: 13px;">.</span></p>
<p>The first thing to do is to Install CsvHelper.  To do this run the following command in the Package Manager Console:</p><pre class="crayon-plain-tag">Install-Package CsvHelper</pre><p><span style="line-height: 19px; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px;">Now add CsvHelper to the program by adding:</span></p><pre class="crayon-plain-tag">using CsvHelper;</pre><p><span style="line-height: 19px; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px;">The next step is to create a class which has properties with the same name of the column headings found in the csv file.  Below you will find an example of a class which does this:</span></p><pre class="crayon-plain-tag">class DataRecord
    {
        //Should have properties which correspond to the Column Names in the file
        //i.e. CommonName,FormalName,TelephoneCode,CountryCode
        public String CommonName { get; set; }
        public String FormalName { get; set; }
        public String TelephoneCode { get; set; }
        public String CountryCode { get; set; }
    }</pre><p><code style="line-height: 19px; font-size: 13px;">Finally create an instance of CSVReader and invoke the GetRecords method using the DataRecord class.  Below you will find an example of this:</code></p><pre class="crayon-plain-tag">var reader = new CsvReader(sr);
IEnumerable&lt;DataRecord&gt; records = reader.GetRecords&lt;DataRecord&gt;();</pre><p><code>An completed example can be found below:</code></p><pre class="crayon-plain-tag">using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using CsvHelper;

namespace CSVHelperReadSample
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            using (var sr = new StreamReader(@&quot;countrylist.csv&quot;))
            {
                var reader = new CsvReader(sr);

                //CSVReader will now read the whole file into an enumerable
                IEnumerable&lt;DataRecord&gt; records = reader.GetRecords&lt;DataRecord&gt;();

                //First 5 records in CSV file will be printed to the Output Window
                foreach (DataRecord record in records.Take(5)) 
                {
                    Debug.Print(&quot;{0} {1}, {2}, {3}&quot;, record.CommonName, record.CountryCode, record.FormalName,
                        record.TelephoneCode);
                }
            }
        }
    }
}</pre><p>You can download this sample code with  <em><strong><a href="http://csvhelper.com">CsvHelper</a> </strong></em>and CSV file here: <a href="http://carlosferreira.com/wp-content/uploads/2013/11/CVSHelperReadSample.zip">CVSHelperReadSample</a></p>
]]></content:encoded>
					
					<wfw:commentRss>http://carlosferreira.com/reading-csv-files-using-csvhelper-package-c-ienumerable/feed/</wfw:commentRss>
			<slash:comments>19</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">226</post-id>	</item>
	</channel>
</rss>
