<?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#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>SQL Kit</title>
	<atom:link href="http://sqlkit.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://sqlkit.com</link>
	<description>SQL Server - Blogs and More</description>
	<lastBuildDate>Fri, 30 Mar 2012 13:03:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='sqlkit.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/5be5b6f7c20e91b9572358448d61018c?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>SQL Kit</title>
		<link>http://sqlkit.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://sqlkit.com/osd.xml" title="SQL Kit" />
	<atom:link rel='hub' href='http://sqlkit.com/?pushpress=hub'/>
		<item>
		<title>SSIS on SYBASE &#8211; Driving Properties From Configurations</title>
		<link>http://sqlkit.com/2010/09/09/ssis-on-sybase-driving-properties-from-configurations/</link>
		<comments>http://sqlkit.com/2010/09/09/ssis-on-sybase-driving-properties-from-configurations/#comments</comments>
		<pubDate>Thu, 09 Sep 2010 01:12:45 +0000</pubDate>
		<dc:creator>ashwaniroy</dc:creator>
				<category><![CDATA[SQL Server 2008]]></category>

		<guid isPermaLink="false">https://sqlkit.wordpress.com/2010/09/09/ssis-on-sybase-driving-properties-from-configurations/</guid>
		<description><![CDATA[So Now that I have a package that works and loads data from a CSV file to a Untyped Table and then a Typed , I think it is the time when we try to find out what is the best (or only) way to use Configuration driven properties. SSIS Gives these way to set [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkit.com&amp;blog=6555210&amp;post=147&amp;subd=sqlkit&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So Now that I have a package that works and loads data from a CSV file to a Untyped Table and then a Typed , I think it is the time when we try to find out what is the best (or only) way to use Configuration driven properties. </p>
<p>SSIS Gives these way to set up config :- </p>
<p>Go to SSIS à Package ConfigurationsàAdd you will see these options </p>
<p><a href="http://sqlkit.files.wordpress.com/2010/09/image0011.jpg"><img style="display:inline;border-width:0;" title="image001 (1)" border="0" alt="image001 (1)" src="http://sqlkit.files.wordpress.com/2010/09/image0011_thumb.jpg?w=531&#038;h=483" width="531" height="483" /></a> </p>
<ul>
<li>I don’t like registry entry, and neither will your System / Database Admin. So I am leaving it there. </li>
<li>Parent Package variable, well don’t want that. </li>
<li>SQL Server Option wont work&#160; because only database I have is Sybase but there is a Bug here which I would like to Point out </li>
</ul>
<p>If you say SQL Server , and select “Specify Configuration Settings Directly” even you Sybase Connection will show up </p>
<p><a href="http://sqlkit.files.wordpress.com/2010/09/image002.jpg"><img style="display:inline;border-width:0;" title="image002" border="0" alt="image002" src="http://sqlkit.files.wordpress.com/2010/09/image002_thumb.jpg?w=573&#038;h=355" width="573" height="355" /></a> </p>
<p>But you wont go too far from here because after you create a new Config table to hold the config values, you wont be able to add the configuration filter. It is a bit dumb because Sybase connection should not surface as SQL Connection if it is not a SQL Connection. But anyway we are left with Environment variable and XML Configuration. </p>
<p>So I would Say </p>
<ol>
<li>Use Env variable to store the path to XML connection </li>
<li>Use XML config to store rest of the properties </li>
</ol>
<p>So Just select the XML Configuration Option </p>
<p><a href="http://sqlkit.files.wordpress.com/2010/09/image003.jpg"><img style="display:inline;border-width:0;" title="image003" border="0" alt="image003" src="http://sqlkit.files.wordpress.com/2010/09/image003_thumb.jpg?w=587&#038;h=512" width="587" height="512" /></a> </p>
<p>3. Select the properties that you want to drive from config. I have selected the connection string here. </p>
<p><a href="http://sqlkit.files.wordpress.com/2010/09/image004.jpg"><img style="display:inline;border-width:0;" title="image004" border="0" alt="image004" src="http://sqlkit.files.wordpress.com/2010/09/image004_thumb.jpg?w=638&#038;h=551" width="638" height="551" /></a> </p>
<p>Next àNext àFinish </p>
<p>Don’t forget to enable package Configuration </p>
<p><a href="http://sqlkit.files.wordpress.com/2010/09/image005.jpg"><img style="display:inline;border-width:0;" title="image005" border="0" alt="image005" src="http://sqlkit.files.wordpress.com/2010/09/image005_thumb.jpg?w=619&#038;h=529" width="619" height="529" /></a> </p>
<ol>
<li>Now Open the Config file(Best way to do which I know is , add to your SSIS Project and Reformat the document using Ctrl+k , Ctrl+D. it will look like </li>
</ol>
<p>&#160;</p>
<pre class="code"><span style="color:blue;">&lt;</span><span style="color:maroon;">Configuration </span><span style="color:red;">ConfiguredType</span>=<span style="color:#a31515;">&quot;Property&quot; </span><span style="color:red;">Path</span>=<span style="color:#a31515;">&quot;\Package.Connections[staging].Properties[ConnectionString]&quot; </span><span style="color:red;">ValueType</span>=<span style="color:#a31515;">&quot;String&quot;</span><span style="color:blue;">&gt;
              &lt;</span><span style="color:maroon;">ConfiguredValue</span><span style="color:blue;">&gt;</span>Data Source=ash-pc:5400;User ID=ash;Password=roy;Initial Catalog=etl;Provider=ASEOLEDB.1;<span style="color:blue;">&lt;/</span><span style="color:maroon;">ConfiguredValue</span><span style="color:blue;">&gt;
       &lt;/</span><span style="color:maroon;">Configuration</span><span style="color:blue;">&gt;
       &lt;</span><span style="color:maroon;">Configuration </span><span style="color:red;">ConfiguredType</span>=<span style="color:#a31515;">&quot;Property&quot; </span><span style="color:red;">Path</span>=<span style="color:#a31515;">&quot;\Package.Connections[staging].Properties[Description]&quot; </span><span style="color:red;">ValueType</span>=<span style="color:#a31515;">&quot;String&quot;</span><span style="color:blue;">&gt;
              &lt;</span><span style="color:maroon;">ConfiguredValue</span><span style="color:blue;">&gt;&lt;/</span><span style="color:maroon;">ConfiguredValue</span><span style="color:blue;">&gt;
       &lt;/</span><span style="color:maroon;">Configuration</span><span style="color:blue;">&gt;
       &lt;</span><span style="color:maroon;">Configuration </span><span style="color:red;">ConfiguredType</span>=<span style="color:#a31515;">&quot;Property&quot; </span><span style="color:red;">Path</span>=<span style="color:#a31515;">&quot;\Package.Connections[staging].Properties[InitialCatalog]&quot; </span><span style="color:red;">ValueType</span>=<span style="color:#a31515;">&quot;String&quot;</span><span style="color:blue;">&gt;
              &lt;</span><span style="color:maroon;">ConfiguredValue</span><span style="color:blue;">&gt;</span>etl <span style="color:blue;">&lt;/</span><span style="color:maroon;">ConfiguredValue</span><span style="color:blue;">&gt;
       &lt;/</span><span style="color:maroon;">Configuration</span><span style="color:blue;">&gt;
       &lt;</span><span style="color:maroon;">Configuration </span><span style="color:red;">ConfiguredType</span>=<span style="color:#a31515;">&quot;Property&quot; </span><span style="color:red;">Path</span>=<span style="color:#a31515;">&quot;\Package.Connections[staging].Properties[Name]&quot; </span><span style="color:red;">ValueType</span>=<span style="color:#a31515;">&quot;String&quot;</span><span style="color:blue;">&gt;
              &lt;</span><span style="color:maroon;">ConfiguredValue</span><span style="color:blue;">&gt;</span>staging<span style="color:blue;">&lt;/</span><span style="color:maroon;">ConfiguredValue</span><span style="color:blue;">&gt;
       &lt;/</span><span style="color:maroon;">Configuration</span><span style="color:blue;">&gt;
       &lt;</span><span style="color:maroon;">Configuration </span><span style="color:red;">ConfiguredType</span>=<span style="color:#a31515;">&quot;Property&quot; </span><span style="color:red;">Path</span>=<span style="color:#a31515;">&quot;\Package.Connections[staging].Properties[Password]&quot; </span><span style="color:red;">ValueType</span>=<span style="color:#a31515;">&quot;String&quot;</span><span style="color:blue;">&gt;
              &lt;</span><span style="color:maroon;">ConfiguredValue</span><span style="color:blue;">&gt;&lt;/</span><span style="color:maroon;">ConfiguredValue</span><span style="color:blue;">&gt;
       &lt;/</span><span style="color:maroon;">Configuration</span><span style="color:blue;">&gt;
       &lt;</span><span style="color:maroon;">Configuration </span><span style="color:red;">ConfiguredType</span>=<span style="color:#a31515;">&quot;Property&quot; </span><span style="color:red;">Path</span>=<span style="color:#a31515;">&quot;\Package.Connections[staging].Properties[ProtectionLevel]&quot; </span><span style="color:red;">ValueType</span>=<span style="color:#a31515;">&quot;Int32&quot;</span><span style="color:blue;">&gt;
              &lt;</span><span style="color:maroon;">ConfiguredValue</span><span style="color:blue;">&gt;</span>1<span style="color:blue;">&lt;/</span><span style="color:maroon;">ConfiguredValue</span><span style="color:blue;">&gt;
       &lt;/</span><span style="color:maroon;">Configuration</span><span style="color:blue;">&gt;
       &lt;</span><span style="color:maroon;">Configuration </span><span style="color:red;">ConfiguredType</span>=<span style="color:#a31515;">&quot;Property&quot; </span><span style="color:red;">Path</span>=<span style="color:#a31515;">&quot;\Package.Connections[staging].Properties[RetainSameConnection]&quot; </span><span style="color:red;">ValueType</span>=<span style="color:#a31515;">&quot;Boolean&quot;</span><span style="color:blue;">&gt;
              &lt;</span><span style="color:maroon;">ConfiguredValue</span><span style="color:blue;">&gt;</span>0<span style="color:blue;">&lt;/</span><span style="color:maroon;">ConfiguredValue</span><span style="color:blue;">&gt;
       &lt;/</span><span style="color:maroon;">Configuration</span><span style="color:blue;">&gt;
       &lt;</span><span style="color:maroon;">Configuration </span><span style="color:red;">ConfiguredType</span>=<span style="color:#a31515;">&quot;Property&quot; </span><span style="color:red;">Path</span>=<span style="color:#a31515;">&quot;\Package.Connections[staging].Properties[ServerName]&quot; </span><span style="color:red;">ValueType</span>=<span style="color:#a31515;">&quot;String&quot;</span><span style="color:blue;">&gt;
              &lt;</span><span style="color:maroon;">ConfiguredValue</span><span style="color:blue;">&gt; </span>ash-pc:5400<span style="color:blue;">&lt;/</span><span style="color:maroon;">ConfiguredValue</span><span style="color:blue;">&gt;
       &lt;/</span><span style="color:maroon;">Configuration</span><span style="color:blue;">&gt;
       &lt;</span><span style="color:maroon;">Configuration </span><span style="color:red;">ConfiguredType</span>=<span style="color:#a31515;">&quot;Property&quot; </span><span style="color:red;">Path</span>=<span style="color:#a31515;">&quot;\Package.Connections[staging].Properties[UserName]&quot; </span><span style="color:red;">ValueType</span>=<span style="color:#a31515;">&quot;String&quot;</span><span style="color:blue;">&gt;
              &lt;</span><span style="color:maroon;">ConfiguredValue</span><span style="color:blue;">&gt;</span>ash<span style="color:blue;">&lt;/</span><span style="color:maroon;">ConfiguredValue</span><span style="color:blue;">&gt;
       &lt;/</span><span style="color:maroon;">Configuration</span><span style="color:blue;">&gt;
       &lt;</span><span style="color:maroon;">Configuration </span><span style="color:red;">ConfiguredType</span>=<span style="color:#a31515;">&quot;Property&quot; </span><span style="color:red;">Path</span>=<span style="color:#a31515;">&quot;\Package.Connections[staging].Properties[Password]&quot; </span><span style="color:red;">ValueType</span>=<span style="color:#a31515;">&quot;String&quot;</span><span style="color:blue;">&gt;
              &lt;</span><span style="color:maroon;">ConfiguredValue</span><span style="color:blue;">&gt;</span>roy<span style="color:blue;">&lt;/</span><span style="color:maroon;">ConfiguredValue</span><span style="color:blue;">&gt;
   &lt;/</span><span style="color:maroon;">Configuration</span><span style="color:blue;">&gt;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a></p>
<p>So If you are using SSIS as ETL on a Datawarehouse that is not Microsoft SQL Server then you can use this as a way to use config driven SSIS . </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlkit.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlkit.wordpress.com/147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlkit.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlkit.wordpress.com/147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlkit.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlkit.wordpress.com/147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlkit.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlkit.wordpress.com/147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlkit.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlkit.wordpress.com/147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlkit.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlkit.wordpress.com/147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlkit.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlkit.wordpress.com/147/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkit.com&amp;blog=6555210&amp;post=147&amp;subd=sqlkit&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlkit.com/2010/09/09/ssis-on-sybase-driving-properties-from-configurations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">ashwaniroy</media:title>
		</media:content>

		<media:content url="http://sqlkit.files.wordpress.com/2010/09/image0011_thumb.jpg" medium="image">
			<media:title type="html">image001 (1)</media:title>
		</media:content>

		<media:content url="http://sqlkit.files.wordpress.com/2010/09/image002_thumb.jpg" medium="image">
			<media:title type="html">image002</media:title>
		</media:content>

		<media:content url="http://sqlkit.files.wordpress.com/2010/09/image003_thumb.jpg" medium="image">
			<media:title type="html">image003</media:title>
		</media:content>

		<media:content url="http://sqlkit.files.wordpress.com/2010/09/image004_thumb.jpg" medium="image">
			<media:title type="html">image004</media:title>
		</media:content>

		<media:content url="http://sqlkit.files.wordpress.com/2010/09/image005_thumb.jpg" medium="image">
			<media:title type="html">image005</media:title>
		</media:content>
	</item>
		<item>
		<title>SSIS on SYBASE &#8211; ASE 15 &#8211; Loading from CSV file to Untyped table and then to Typed Table</title>
		<link>http://sqlkit.com/2010/09/08/ssis-on-sybase-ase-15-loading-from-csv-file-to-untyped-table-and-then-to-typed-table/</link>
		<comments>http://sqlkit.com/2010/09/08/ssis-on-sybase-ase-15-loading-from-csv-file-to-untyped-table-and-then-to-typed-table/#comments</comments>
		<pubDate>Tue, 07 Sep 2010 23:20:27 +0000</pubDate>
		<dc:creator>ashwaniroy</dc:creator>
				<category><![CDATA[SQL Server 2008]]></category>

		<guid isPermaLink="false">https://sqlkit.wordpress.com/2010/09/08/ssis-on-sybase-ase-15-loading-from-csv-file-to-untyped-table-and-then-to-typed-table/</guid>
		<description><![CDATA[This is first of my series on SSIS of Sybase ASE 15 . 1. Create table to hold this data --Create a typed and Untyped table --Typed Table create table foo ( book_id int not null , book_code varchar(16) not null , desk_id int not null ) --Untyped Table Create table bar ( book_id varchar(50) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkit.com&amp;blog=6555210&amp;post=136&amp;subd=sqlkit&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is first of my series on SSIS of Sybase ASE 15 . </p>
<pre class="code"><span style="color:green;"><font size="3" face="Consolas">1.  Create table to hold this data</font></span></pre>
<pre class="code"><font size="3"><font face="Consolas"><span style="color:green;">--Create a typed and Untyped table
--Typed Table
</span><span style="color:blue;">create table </span>foo </font></font><font size="3"><font face="Consolas"><span style="color:gray;">(
       </span>book_id                         <span style="color:blue;">int                              </span></font></font><font size="3"><font face="Consolas"><span style="color:gray;">not null  ,
       </span>book_code                       <span style="color:blue;">varchar</span><span style="color:gray;">(</span>16</font></font><font size="3"><font face="Consolas"><span style="color:gray;">)                      not null  ,
       </span>desk_id                         <span style="color:blue;">int                              </span></font></font><span style="color:gray;"><font size="3" face="Consolas">not null
)
</font></span><font size="3"><font face="Consolas"><span style="color:green;">--Untyped Table
</span><span style="color:blue;">Create table </span>bar </font></font><font size="3"><font face="Consolas"><span style="color:gray;">(
       </span>book_id                         <span style="color:blue;">varchar</span><span style="color:gray;">(</span>50</font></font><font size="3"><font face="Consolas"><span style="color:gray;">)                      not null  ,
       </span>book_code                       <span style="color:blue;">varchar</span><span style="color:gray;">(</span>50</font></font><font size="3"><font face="Consolas"><span style="color:gray;">)                      not null  ,
       </span>desk_id                         <span style="color:blue;">varchar</span><span style="color:gray;">(</span>50</font></font><span style="color:gray;"><font size="3" face="Consolas">)                      not null
)
</font></span><font size="3"><font face="Consolas"><span style="color:green;">--Error Table
</span><span style="color:blue;">Create table </span>error </font></font><font size="3"><font face="Consolas"><span style="color:gray;">(
       </span>book_id                         <span style="color:blue;">varchar</span><span style="color:gray;">(</span>50</font></font><font size="3"><font face="Consolas"><span style="color:gray;">)                      not null  ,
       </span>book_code                       <span style="color:blue;">varchar</span><span style="color:gray;">(</span>50</font></font><font size="3"><font face="Consolas"><span style="color:gray;">)                      not null  ,
       </span>desk_id                         <span style="color:blue;">varchar</span><span style="color:gray;">(</span>50</font></font><font size="3"><font face="Consolas"><span style="color:gray;">)                      not null  ,
       </span>error_code                      <span style="color:blue;">varchar</span><span style="color:gray;">(</span>256</font></font><span style="color:gray;"><font size="3" face="Consolas">)                         null
)</font></span></pre>
<ol>
<li>Use these 3 records as your test.csv file </li>
</ol>
<p>1,AMSTMM,23</p>
<p>2,CBOND,9</p>
<p>CMD,CBOND,DBO</p>
<ol>
<li>Add a new connection to the connection Manager of the type Native OLEDB\Sybase ILEDB Provider </li>
<li>Configure the Connection Provider’s Property </li>
</ol>
<p><a href="http://sqlkit.files.wordpress.com/2010/09/1.jpg"><img style="display:inline;border-width:0;" title="1" border="0" alt="1" src="http://sqlkit.files.wordpress.com/2010/09/1_thumb.jpg?w=336&#038;h=353" width="336" height="353" /></a> </p>
<ol>
<li>Add a new Connection Manager for Flat File Source for the CSV file test.csv. Name it CSV </li>
</ol>
<p>That’s all you need in set up</p>
<ol>
<li>Drag and drop a Data Flow Task and Open it </li>
<li>Add a Flat file source component and configure it to point to the CSV connection </li>
<li>Drag a OLEDB Destination and configure it to use the Sybase connection and use dbo.bar as the destination table </li>
</ol>
<p><a href="http://sqlkit.files.wordpress.com/2010/09/2.jpg"><img style="display:inline;border-width:0;" title="2" border="0" alt="2" src="http://sqlkit.files.wordpress.com/2010/09/2_thumb.jpg?w=499&#038;h=377" width="499" height="377" /></a> </p>
<ol>
<li>Run the task and it has succeeded your data will be in the table </li>
</ol>
<p><a href="http://sqlkit.files.wordpress.com/2010/09/3.jpg"><img style="display:inline;border-width:0;" title="3" border="0" alt="3" src="http://sqlkit.files.wordpress.com/2010/09/3_thumb.jpg?w=373&#038;h=307" width="373" height="307" /></a> </p>
<p><a href="http://sqlkit.files.wordpress.com/2010/09/4.jpg"><img style="display:inline;border-width:0;" title="4" border="0" alt="4" src="http://sqlkit.files.wordpress.com/2010/09/4_thumb.jpg?w=479&#038;h=145" width="479" height="145" /></a> </p>
<ol>
<li>Ok So far so good. Now I want to load it to Typed Table. Drag another dataflow task for this and Open it. </li>
<li>Drag a OLEDB Source and Point it to dbo.bar and Drag a OLEDB destination and point it to dbo.foo and connect it and Map the columns. Done !! IS it ? Watch this.. </li>
</ol>
<p>When You execute this task this is what will happen</p>
<ol>
<li>Task will look like this </li>
</ol>
<p><a href="http://sqlkit.files.wordpress.com/2010/09/5.jpg"><img style="display:inline;border-width:0;" title="5" border="0" alt="5" src="http://sqlkit.files.wordpress.com/2010/09/5_thumb.jpg?w=366&#038;h=324" width="366" height="324" /></a> </p>
<p>So it failed !! Ya I expected it to because of the Bad typed row in the untyped. But that is not what I want to show you. This is what I want to show you </p>
<ol>
<li>Log will be saying </li>
</ol>
<p>&#160;&#160;&#160; An OLE DB error has occurred. Error code: 0&#215;80020005.</p>
<p>The ProcessInput method on component &quot;typed&quot; (42) failed with error code 0xC0202009. The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running.</p>
<p>Thread &quot;WorkThread0&quot; has exited with error code 0xC0202009.</p>
<ol>
<li><b><u>The Error Message clearly is not really helpful from the Sybase Adapter. Grrrr!!</u></b> </li>
<li>2.And further down the line you will see this </li>
<li>OnInformation,FMDX2622,MARKETS\c001334,Package,{40CB9E75-B873-45C7-8129-D74D85F567FC},{5B329EA9-3798-44A0-B3DC-1EAF61F204B7},07/09/10 11:10:45,07/09/10 11:10:45,1074016267,0x,&quot;component &quot;typed&quot; (42)&quot; wrote 2 rows. </li>
</ol>
<ol>
<li>Now that it is saying that it loaded 2 rows lets look at the Database. </li>
</ol>
<p><a href="http://sqlkit.files.wordpress.com/2010/09/6.jpg"><img style="display:inline;border-width:0;" title="6" border="0" alt="6" src="http://sqlkit.files.wordpress.com/2010/09/6_thumb.jpg?w=369&#038;h=85" width="369" height="85" /></a> </p>
<p>Huh!! How did the Row -3 with first and last column casted to 0 came here. I did not do any type casting and also log said only 2 rows are inserted.</p>
<p>Well that is either a problem with Sybase Adapter for Oledb for returning and SSIS and the way it treats Sybase data type.</p>
<p>Lets look more deep in the Sybase OLEDB Destination Component.(Right Click à Show Advance Editor)</p>
<p>Book_id is INTEGER column so that’s what the External Column says .. No problem there.</p>
<p><a href="http://sqlkit.files.wordpress.com/2010/09/7.jpg"><img style="display:inline;border-width:0;" title="7" border="0" alt="7" src="http://sqlkit.files.wordpress.com/2010/09/7_thumb.jpg?w=533&#038;h=292" width="533" height="292" /></a> </p>
<p>Now look at book_id in&#160; Input Columns</p>
<p><a href="http://sqlkit.files.wordpress.com/2010/09/8.jpg"><img style="display:inline;border-width:0;" title="8" border="0" alt="8" src="http://sqlkit.files.wordpress.com/2010/09/8_thumb.jpg?w=544&#038;h=364" width="544" height="364" /></a> </p>
<p>How is that chaged to DT_STR. This is the reason why the load it doing implicit cast. The Bug is with the Sybase Adapter as well which then commits another mistake of returning the wrong count of inserted rows.</p>
<p>Ok So how do I fix it. Well by explicit typing using Data Conversion task. Here is the solution.</p>
<ol>
<li>Add a data conversion task in between Source(bar) and destination(foo) . If you want you can add a error redirect to error </li>
</ol>
<p><a href="http://sqlkit.files.wordpress.com/2010/09/9.jpg"><img style="display:inline;border-width:0;" title="9" border="0" alt="9" src="http://sqlkit.files.wordpress.com/2010/09/9_thumb.jpg?w=498&#038;h=403" width="498" height="403" /></a> </p>
<ol>
<li>Data conversion task basically takes the column from the UnType and casts them to explicit types. On Error while casting it redirects it to error table which is untyped as given above. Correct rows are loaded to Typed. </li>
<li>This is what the Data Conversion Task looks like </li>
</ol>
<p><a href="http://sqlkit.files.wordpress.com/2010/09/10.jpg"><img style="display:inline;border-width:0;" title="10" border="0" alt="10" src="http://sqlkit.files.wordpress.com/2010/09/10_thumb.jpg?w=533&#038;h=372" width="533" height="372" /></a> </p>
<ol>
<li>Run this and verify the results. Mine looked my fav color GREEN </li>
</ol>
<p><a href="http://sqlkit.files.wordpress.com/2010/09/11.jpg"><img style="display:inline;border-width:0;" title="11" border="0" alt="11" src="http://sqlkit.files.wordpress.com/2010/09/11_thumb.jpg?w=552&#038;h=338" width="552" height="338" /></a> </p>
<ol>
<li>Logs also return what has actually been done </li>
</ol>
<p>OnInformation,ash-pc,Foo\c001334,Package,{40CB9E75-B873-45C7-8129-D74D85F567FC},{16316E6B-94DA-4235-B27E-10EF3E472E38},07/09/10 11:31:35,07/09/10 11:31:35,1074016267,0x,&quot;component &quot;typed&quot; (42)&quot; wrote 2 rows.</p>
<p>OnInformation,ash-pc,Foo\c001334,Package,{40CB9E75-B873-45C7-8129-D74D85F567FC},{16316E6B-94DA-4235-B27E-10EF3E472E38},07/09/10 11:31:35,07/09/10 11:31:35,1074016267,0x,&quot;component &quot;Error&quot; (1004)&quot; wrote 1 rows.</p>
<ol>
<li>Database looks like this </li>
</ol>
<p>Foo</p>
<p><a href="http://sqlkit.files.wordpress.com/2010/09/12.jpg"><img style="display:inline;border-width:0;" title="12" border="0" alt="12" src="http://sqlkit.files.wordpress.com/2010/09/12_thumb.jpg?w=511&#038;h=86" width="511" height="86" /></a> </p>
<p>Error</p>
<p><a href="http://sqlkit.files.wordpress.com/2010/09/13.jpg"><img style="display:inline;border-width:0;" title="13" border="0" alt="13" src="http://sqlkit.files.wordpress.com/2010/09/13_thumb.jpg?w=528&#038;h=33" width="528" height="33" /></a> </p>
<p>Job Done!!</p>
<p>Loading UnTyped To Typed is a very common pattern and perhaps this will help someone to do this for SYBASE ASE-15 and SSIS. (Both 2005 and 200</p>
<p><a href="http://11011.net/software/vspaste"></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlkit.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlkit.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlkit.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlkit.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlkit.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlkit.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlkit.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlkit.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlkit.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlkit.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlkit.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlkit.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlkit.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlkit.wordpress.com/136/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkit.com&amp;blog=6555210&amp;post=136&amp;subd=sqlkit&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlkit.com/2010/09/08/ssis-on-sybase-ase-15-loading-from-csv-file-to-untyped-table-and-then-to-typed-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">ashwaniroy</media:title>
		</media:content>

		<media:content url="http://sqlkit.files.wordpress.com/2010/09/1_thumb.jpg" medium="image">
			<media:title type="html">1</media:title>
		</media:content>

		<media:content url="http://sqlkit.files.wordpress.com/2010/09/2_thumb.jpg" medium="image">
			<media:title type="html">2</media:title>
		</media:content>

		<media:content url="http://sqlkit.files.wordpress.com/2010/09/3_thumb.jpg" medium="image">
			<media:title type="html">3</media:title>
		</media:content>

		<media:content url="http://sqlkit.files.wordpress.com/2010/09/4_thumb.jpg" medium="image">
			<media:title type="html">4</media:title>
		</media:content>

		<media:content url="http://sqlkit.files.wordpress.com/2010/09/5_thumb.jpg" medium="image">
			<media:title type="html">5</media:title>
		</media:content>

		<media:content url="http://sqlkit.files.wordpress.com/2010/09/6_thumb.jpg" medium="image">
			<media:title type="html">6</media:title>
		</media:content>

		<media:content url="http://sqlkit.files.wordpress.com/2010/09/7_thumb.jpg" medium="image">
			<media:title type="html">7</media:title>
		</media:content>

		<media:content url="http://sqlkit.files.wordpress.com/2010/09/8_thumb.jpg" medium="image">
			<media:title type="html">8</media:title>
		</media:content>

		<media:content url="http://sqlkit.files.wordpress.com/2010/09/9_thumb.jpg" medium="image">
			<media:title type="html">9</media:title>
		</media:content>

		<media:content url="http://sqlkit.files.wordpress.com/2010/09/10_thumb.jpg" medium="image">
			<media:title type="html">10</media:title>
		</media:content>

		<media:content url="http://sqlkit.files.wordpress.com/2010/09/11_thumb.jpg" medium="image">
			<media:title type="html">11</media:title>
		</media:content>

		<media:content url="http://sqlkit.files.wordpress.com/2010/09/12_thumb.jpg" medium="image">
			<media:title type="html">12</media:title>
		</media:content>

		<media:content url="http://sqlkit.files.wordpress.com/2010/09/13_thumb.jpg" medium="image">
			<media:title type="html">13</media:title>
		</media:content>
	</item>
		<item>
		<title>SSIS on Sybase ASE 15</title>
		<link>http://sqlkit.com/2010/09/08/ssis-on-sybase-ase-15/</link>
		<comments>http://sqlkit.com/2010/09/08/ssis-on-sybase-ase-15/#comments</comments>
		<pubDate>Tue, 07 Sep 2010 21:55:36 +0000</pubDate>
		<dc:creator>ashwaniroy</dc:creator>
				<category><![CDATA[SQL Server 2008]]></category>

		<guid isPermaLink="false">https://sqlkit.wordpress.com/2010/09/08/ssis-on-sybase-ase-15/</guid>
		<description><![CDATA[I have decided to post couple of blog entries on SSIS with Sybase. This is because my the datawarehouse that I am working on is on SYBASE ASE – 15 but I have decided to use SSIS (not because I am a MVP or Microsoft fanatic but just because I love the tool (mostly) and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkit.com&amp;blog=6555210&amp;post=109&amp;subd=sqlkit&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have decided to post couple of blog entries on SSIS with Sybase. This is because my the datawarehouse that I am working on is on SYBASE ASE – 15 but I have decided to use SSIS (not because I am a MVP or Microsoft fanatic but just because I love the tool (mostly) and we can do pretty much anything that we can with any other ETL tool.</p>
<p>So watch out for the next few entries</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlkit.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlkit.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlkit.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlkit.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlkit.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlkit.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlkit.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlkit.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlkit.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlkit.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlkit.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlkit.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlkit.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlkit.wordpress.com/109/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkit.com&amp;blog=6555210&amp;post=109&amp;subd=sqlkit&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlkit.com/2010/09/08/ssis-on-sybase-ase-15/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">ashwaniroy</media:title>
		</media:content>
	</item>
		<item>
		<title>Speaking at SQL Bits 7 &#8211; University Of York OCT 2</title>
		<link>http://sqlkit.com/2010/08/12/speaking-at-sql-bits-7-university-of-york-oct-2/</link>
		<comments>http://sqlkit.com/2010/08/12/speaking-at-sql-bits-7-university-of-york-oct-2/#comments</comments>
		<pubDate>Thu, 12 Aug 2010 14:01:49 +0000</pubDate>
		<dc:creator>ashwaniroy</dc:creator>
				<category><![CDATA[SQL Server 2008]]></category>

		<guid isPermaLink="false">https://sqlkit.wordpress.com/2010/08/12/speaking-at-sql-bits-7-university-of-york-oct-2/</guid>
		<description><![CDATA[Agenda for SQL Bits 7 has been announced. This has a similar format as SQLBits 5 i.e a 2 day session. Friday 1st Oct is the paid session with speakers Buck Woody, SQL Server Technical Specialist at Microsoft Thomas Kejser, Microsoft SQLCAT team Brent Ozar Brad McGehee Chris Testa-O’Neill Simon Sabin Chris Webb Allan Mitchell [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkit.com&amp;blog=6555210&amp;post=108&amp;subd=sqlkit&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Agenda for SQL Bits 7 has been announced. This has a similar format as SQLBits 5 i.e a 2 day session. Friday 1st Oct is the paid session with speakers </p>
<ul>
<li>Buck Woody, SQL Server Technical Specialist at Microsoft </li>
<li>Thomas Kejser, Microsoft SQLCAT team </li>
<li>Brent Ozar </li>
<li>Brad McGehee </li>
<li>Chris Testa-O’Neill </li>
<li>Simon Sabin </li>
<li>Chris Webb </li>
<li>Allan Mitchell </li>
<li>Martin Bell </li>
</ul>
<p>Go to <a href="http://www.sqlbits.com">www.sqlbits.com</a> for more information.</p>
<p>I will be speaking in the free community day session which is on 2nd October on Analysis Services Best Practices.This includes the things that I have picked up on the job and encompasses areas like attribute relationships , aggregations and some tips and tricks.</p>
<p>I hope you all would enjoy the event and hope to see you guys there.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlkit.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlkit.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlkit.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlkit.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlkit.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlkit.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlkit.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlkit.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlkit.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlkit.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlkit.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlkit.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlkit.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlkit.wordpress.com/108/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkit.com&amp;blog=6555210&amp;post=108&amp;subd=sqlkit&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlkit.com/2010/08/12/speaking-at-sql-bits-7-university-of-york-oct-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">ashwaniroy</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL Bits demos and slides available for download</title>
		<link>http://sqlkit.com/2010/05/12/sql-bits-demos-and-slides-available-for-download/</link>
		<comments>http://sqlkit.com/2010/05/12/sql-bits-demos-and-slides-available-for-download/#comments</comments>
		<pubDate>Wed, 12 May 2010 00:31:37 +0000</pubDate>
		<dc:creator>ashwaniroy</dc:creator>
				<category><![CDATA[SQL Server 2008]]></category>

		<guid isPermaLink="false">https://sqlkit.wordpress.com/2010/05/12/sql-bits-demos-and-slides-available-for-download/</guid>
		<description><![CDATA[So finally I have got all my demos and slides together . SQL Bits and attending SQL Bits in person is an incredible experience and I want to thank all attendees who attended my session and thanks a lot for your feedback. It is very encouraging. You can download the slides from here.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkit.com&amp;blog=6555210&amp;post=106&amp;subd=sqlkit&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So finally I have got all my demos and slides together . SQL Bits and attending SQL Bits in person is an incredible experience and I want to thank all attendees who attended my session and thanks a lot for your feedback. It is very encouraging.</p>
<p>You can download the slides from <a href="http://cid-b805c4eb6abb1c00.skydrive.live.com/self.aspx/SQL%20Bits%206.0/MDX%20On%20Steriods-NEW%20PPT.pptx">here</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlkit.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlkit.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlkit.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlkit.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlkit.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlkit.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlkit.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlkit.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlkit.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlkit.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlkit.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlkit.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlkit.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlkit.wordpress.com/106/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkit.com&amp;blog=6555210&amp;post=106&amp;subd=sqlkit&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlkit.com/2010/05/12/sql-bits-demos-and-slides-available-for-download/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">ashwaniroy</media:title>
		</media:content>
	</item>
		<item>
		<title>Speaking at SQL Bits 6 &#8211; LONDON</title>
		<link>http://sqlkit.com/2010/04/15/speaking-at-sql-bits-6-london/</link>
		<comments>http://sqlkit.com/2010/04/15/speaking-at-sql-bits-6-london/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 21:23:52 +0000</pubDate>
		<dc:creator>ashwaniroy</dc:creator>
				<category><![CDATA[SQL Server 2008]]></category>

		<guid isPermaLink="false">http://sqlkit.wordpress.com/2010/04/15/speaking-at-sql-bits-6-london/</guid>
		<description><![CDATA[I will be speaking at the SQLBits conference in London on April 16th.&#160; My talk will be a 300-level talk on how to use MDX studio to performance tune MDX queries. There are many very interesting session on performance and scalability from very famous speakers like Connor Cunningham (Senior Principal Architect From SQL query processor [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkit.com&amp;blog=6555210&amp;post=105&amp;subd=sqlkit&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I will be speaking at the SQLBits conference in London on April 16th.&#160; My talk will be a 300-level talk on how to use MDX studio to performance tune MDX queries. </p>
<p>There are many very interesting session on performance and scalability from very famous speakers like Connor Cunningham (Senior Principal Architect From SQL query processor team),Chirs Webb(SQL MVP , author and Internationally renowned speaker,Keith Burns&#160; and many more. </p>
<p>I hope to see some of you there! </p>
<p>You can read more about this and the other talks at <a href="http://www.sqlbits.com/information/PublicSessions.aspx">http://www.sqlbits.com/information/PublicSessions.aspx</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlkit.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlkit.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlkit.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlkit.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlkit.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlkit.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlkit.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlkit.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlkit.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlkit.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlkit.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlkit.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlkit.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlkit.wordpress.com/105/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkit.com&amp;blog=6555210&amp;post=105&amp;subd=sqlkit&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlkit.com/2010/04/15/speaking-at-sql-bits-6-london/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">ashwaniroy</media:title>
		</media:content>
	</item>
		<item>
		<title>A Generic Untyped To Typed Table Load which does automatic Type Checking and error redirection</title>
		<link>http://sqlkit.com/2010/04/11/a-generic-untyped-to-typed-table-load-which-does-automatic-type-checking-and-error-redirection-2/</link>
		<comments>http://sqlkit.com/2010/04/11/a-generic-untyped-to-typed-table-load-which-does-automatic-type-checking-and-error-redirection-2/#comments</comments>
		<pubDate>Sat, 10 Apr 2010 21:28:02 +0000</pubDate>
		<dc:creator>ashwaniroy</dc:creator>
				<category><![CDATA[SQL Server 2008]]></category>

		<guid isPermaLink="false">http://sqlkit.wordpress.com/2010/04/11/a-generic-untyped-to-typed-table-load-which-does-automatic-type-checking-and-error-redirection-2/</guid>
		<description><![CDATA[Loading data from untyped tables to tables is a very frequently occurring scenario in a Data warehouse application.Normally we load all the data we need in a table which is NVARCHAR or VARCHAR column and then check , row-by-row if all the data satisfies the data type check. If the row passes the type check [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkit.com&amp;blog=6555210&amp;post=104&amp;subd=sqlkit&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="line-height:normal;margin-bottom:16.2pt;background:white;" class="MsoNormal"><span style="font-family:consolas;color:#444444;font-size:12pt;"><font size="2" face="ver">Loading data from untyped tables to tables is a very frequently occurring scenario in a Data warehouse application.Normally we load all the data we need in a table which is NVARCHAR or VARCHAR column and then check , row-by-row if all the data satisfies the data type check. If the row passes the type check validation then it is loaded to the typed else it is flagged as INVALID and / or is redirected to another table where we have error out records. So far , so good…But there are few things which are quite painful about this processes. </font></span></p>
<p><font size="2" face="ver"></font></p>
</p>
<p><font face="ver"></font></p>
<p style="line-height:normal;margin-bottom:16.2pt;background:white;" class="MsoNormal"><span style="font-family:consolas;color:#444444;font-size:12pt;"><font size="2" face="ver">No 1:- You have to write some kind of LOOP operation for this . </font></span></p>
<p><font size="2" face="ver"></font></p>
</p>
<p><font face="ver"></font></p>
<p style="line-height:normal;margin-bottom:16.2pt;background:white;" class="MsoNormal"><span style="font-family:consolas;color:#444444;font-size:12pt;"><font size="2" face="ver">No 2:- You need to write code for each untyped to typed table load. </font></span></p>
<p><font size="2" face="ver"></font></p>
</p>
<p><font face="ver"></font></p>
<p style="line-height:normal;margin-bottom:16.2pt;background:white;" class="MsoNormal"><span style="font-family:consolas;color:#444444;font-size:12pt;"><font size="2" face="ver">Even if you use SSIS and use error redirect the INSERT operation becomes row-by-row and no longer is set based which again hits the performance. </font></span></p>
<p><font size="2" face="ver"></font></p>
</p>
<p><font face="ver"></font></p>
<p style="line-height:normal;margin-bottom:16.2pt;background:white;" class="MsoNormal"><span style="font-family:consolas;color:#444444;font-size:12pt;"><font size="2" face="ver">If we look at the problem scenario we have </font></span></p>
<p><font size="2" face="ver"></font></p>
</p>
<p><font face="ver"></font></p>
<p style="line-height:normal;margin-bottom:16.2pt;background:white;" class="MsoNormal"><span style="font-family:consolas;color:#444444;font-size:12pt;"><font size="2" face="ver">1. A Untyped Table </font></span></p>
<p><font size="2" face="ver"></font></p>
</p>
<p><font face="ver"></font></p>
<p style="line-height:normal;margin-bottom:16.2pt;background:white;" class="MsoNormal"><span style="font-family:consolas;color:#444444;font-size:12pt;"><font size="2" face="ver">2. A Typed Table </font></span></p>
<p><font size="2" face="ver"></font></p>
</p>
<p><font face="ver"></font></p>
<p style="line-height:normal;margin-bottom:16.2pt;background:white;" class="MsoNormal"><span style="font-family:consolas;color:#444444;font-size:12pt;"><font size="2" face="ver">3. A Flag Column to mark Invalid records </font></span></p>
<p><font size="2" face="ver"></font></p>
</p>
<p><font face="ver"></font></p>
<p style="line-height:normal;margin-bottom:16.2pt;background:white;" class="MsoNormal"><span style="font-family:consolas;color:#444444;font-size:12pt;"><font size="2" face="ver">4. A table where all errors go </font></span></p>
<p><font size="2" face="ver"></font></p>
</p>
<p><font face="ver"></font></p>
<p style="line-height:normal;margin-bottom:16.2pt;background:white;" class="MsoNormal"><span style="font-family:consolas;color:#444444;font-size:12pt;"><font size="2" face="ver">I am going to try to write a Stored Procedure that does that just. Pass any typed table to it and untyped typed and / or error table , Is_Valid column name (the 4 parameters mentioned above) and it will just find out all the rows that satisfy the type check validation and load then to typed table and will mark the other rows as invalid. </font></span></p>
<p><font size="2" face="ver"></font></p>
</p>
<p><font face="ver"></font></p>
<p style="line-height:normal;margin-bottom:16.2pt;background:white;" class="MsoNormal"><span style="font-family:consolas;color:#444444;font-size:12pt;"><font size="2" face="ver">So as long as you pass the typed table name and corresponding untyped table name , where all the column of typed table are in the untyped table then this SP should work . </font></span></p>
<p><font size="2" face="ver"></font></p>
</p>
<p><font face="ver"></font></p>
<p style="line-height:normal;margin-bottom:16.2pt;background:white;" class="MsoNormal"><span style="font-family:consolas;color:#444444;font-size:12pt;"><font size="2" face="ver">Lets Create 2 tables Untyped and Typed </font></span></p>
<pre class="code"><span style="color:blue;">CREATE  TABLE </span>UNTYPED
<span style="color:gray;">(
 </span>ID      <span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span>20<span style="color:gray;">)
,</span>TITLE   <span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span>20<span style="color:gray;">)
,</span>NAME    <span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span>20<span style="color:gray;">)
,</span>SALARY  <span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span>20<span style="color:gray;">)
,</span>IS_VALID <span style="color:blue;">BIT
</span><span style="color:gray;">) 

</span><span style="color:blue;">CREATE  TABLE </span>TYPED
<span style="color:gray;">(
 </span>ID      <span style="color:blue;">INT
</span><span style="color:gray;">,</span>TITLE   <span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span>20<span style="color:gray;">)
,</span>NAME    <span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span>20<span style="color:gray;">)
,</span>SALARY  <span style="color:blue;">FLOAT
</span><span style="color:gray;">) 

</span><span style="color:blue;">INSERT INTO </span>UNTYPED <span style="color:blue;">VALUES</span><span style="color:gray;">(</span><span style="color:red;">'1'</span><span style="color:gray;">,</span><span style="color:red;">'Mr'</span><span style="color:gray;">,</span><span style="color:red;">'Ash'</span><span style="color:gray;">,</span><span style="color:red;">'100.00'</span><span style="color:gray;">,NULL)
</span><span style="color:blue;">INSERT INTO </span>UNTYPED <span style="color:blue;">VALUES</span><span style="color:gray;">(</span><span style="color:red;">'2'</span><span style="color:gray;">,</span><span style="color:red;">'Mr'</span><span style="color:gray;">,</span><span style="color:red;">'John'</span><span style="color:gray;">,</span><span style="color:red;">'300.00'</span><span style="color:gray;">,NULL)
</span><span style="color:blue;">INSERT INTO </span>UNTYPED <span style="color:blue;">VALUES</span><span style="color:gray;">(</span><span style="color:red;">'3'</span><span style="color:gray;">,</span><span style="color:red;">'Mr'</span><span style="color:gray;">,</span><span style="color:red;">'Doe'</span><span style="color:gray;">,</span><span style="color:red;">'400.00'</span><span style="color:gray;">,NULL)
</span><span style="color:blue;">INSERT INTO </span>UNTYPED <span style="color:blue;">VALUES</span><span style="color:gray;">(</span><span style="color:red;">'4'</span><span style="color:gray;">,</span><span style="color:red;">'Mr'</span><span style="color:gray;">,</span><span style="color:red;">'Bell'</span><span style="color:gray;">,</span><span style="color:red;">'500.00'</span><span style="color:gray;">,NULL)
</span><span style="color:blue;">INSERT INTO </span>UNTYPED <span style="color:blue;">VALUES</span><span style="color:gray;">(</span><span style="color:red;">'5'</span><span style="color:gray;">,</span><span style="color:red;">'Mr'</span><span style="color:gray;">,</span><span style="color:red;">'Jack'</span><span style="color:gray;">,</span><span style="color:red;">'150.00'</span><span style="color:gray;">,NULL)
</span><span style="color:blue;">INSERT INTO </span>UNTYPED <span style="color:blue;">VALUES</span><span style="color:gray;">(</span><span style="color:red;">'6'</span><span style="color:gray;">,</span><span style="color:red;">'Miss'</span><span style="color:gray;">,</span><span style="color:red;">'Jane'</span><span style="color:gray;">,</span><span style="color:red;">'200.00'</span><span style="color:gray;">,NULL)
</span><span style="color:blue;">INSERT INTO </span>UNTYPED <span style="color:blue;">VALUES</span><span style="color:gray;">(</span><span style="color:red;">'7'</span><span style="color:gray;">,</span><span style="color:red;">'Mrs'</span><span style="color:gray;">,</span><span style="color:red;">'Ann'</span><span style="color:gray;">,</span><span style="color:red;">'130.00'</span><span style="color:gray;">,NULL)
</span><span style="color:blue;">INSERT INTO </span>UNTYPED <span style="color:blue;">VALUES</span><span style="color:gray;">(</span><span style="color:red;">'8'</span><span style="color:gray;">,</span><span style="color:red;">'12'</span><span style="color:gray;">,</span><span style="color:red;">'Judy'</span><span style="color:gray;">,</span><span style="color:red;">'Foo'</span><span style="color:gray;">,NULL)
</span><span style="color:blue;">INSERT INTO </span>UNTYPED <span style="color:blue;">VALUES</span><span style="color:gray;">(</span><span style="color:red;">'Bar'</span><span style="color:gray;">,</span><span style="color:red;">'13'</span><span style="color:gray;">,</span><span style="color:red;">'Jude'</span><span style="color:gray;">,</span><span style="color:red;">'BAR'</span><span style="color:gray;">,NULL) </span></pre>
<p><a href="http://11011.net/software/vspaste"></a><span style="font-family:consolas;color:#444444;font-size:12pt;"></p>
<p></span></p>
<p style="line-height:normal;margin-bottom:0;background:white;" class="MsoNormal"><span style="font-family:consolas;color:green;font-size:10pt;">So The Data in the untyped table Now is</span><span style="font-family:consolas;color:#444444;font-size:12pt;"> </span></p>
</p>
</p>
<p style="line-height:normal;margin-bottom:16.2pt;background:white;" class="MsoNormal"><a href="\Users\Ashwani.Roy\AppData\Local\Temp\WindowsLiveWriter1286139640\supfiles20FE865\untyped%5b4%5d.jpg"><span style="font-family:consolas;color:#0066a7;font-size:12pt;text-decoration:none;"><span><img style="display:inline;border-width:0;" title="clip_image001" border="0" alt="clip_image001" src="http://sqlkit.files.wordpress.com/2010/04/clip_image0011.jpg?w=522&#038;h=249" width="522" height="249" /></span></span></a><span style="font-family:consolas;color:#444444;font-size:12pt;"> </span></p>
</p>
</p>
<p style="line-height:normal;margin-bottom:16.2pt;background:white;" class="MsoNormal"><span style="font-family:consolas;color:#444444;font-size:12pt;">&#160; </span></p>
</p>
</p>
<p style="line-height:normal;margin-bottom:16.2pt;background:white;" class="MsoNormal"><span style="font-family:consolas;color:#444444;font-size:12pt;"><font size="2" face="ver">So This is this is the SP . Pleas read the comments. You may have to extend it a bit and might like to add more error handling etc.</font> </span></p>
</p>
</p>
<p style="line-height:normal;margin-bottom:16.2pt;background:white;" class="MsoNormal"><span style="font-family:consolas;color:#444444;font-size:12pt;"></span></p>
<pre class="code"><span style="color:blue;">SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE </span>[dbo]<span style="color:gray;">.</span>[usp_load_untyped_to_typed_staging]
                   @stg_unTyped_table_name <span style="color:blue;">NVARCHAR</span><span style="color:gray;">(</span>256<span style="color:gray;">)
                 , </span>@stg_Typed_table_name <span style="color:blue;">NVARCHAR</span><span style="color:gray;">(</span>256<span style="color:gray;">)
                 , </span>@is_valid_column_name    <span style="color:blue;">NVARCHAR</span><span style="color:gray;">(</span>256<span style="color:gray;">)
                 , </span>@i_debugOnly <span style="color:blue;">INT </span><span style="color:gray;">= </span>0
<span style="color:blue;">AS
</span><span style="color:green;">/**
 * &lt;Example&gt;
   EXEC  [dbo].[usp_load_untyped_to_typed_staging]
                 @stg_typed_table_name     =  'typed'
                ,@stg_unTyped_table_name   =  'untyped'
                ,@is_valid_column_name     =  'IS_VALID'
                ,@i_debugOnly               =   1

 * &lt;Comment&gt;.
 * As of now it does type checking for only INT and FLOAT bit it can be easily extended
 * It does not do NOT NULL Validation as of now  but it can be extended
 * ----------------
 *
 * Ver    Author            Date        Comments
 * ---    -------------------    -----------    ------------------------------
 *   1    Ashwani Roy     09-04-2010   Load From Untyped Staging to Typed Staging with type checking and error flagging
 */
</span><span style="color:blue;">SET NOCOUNT ON</span><span style="color:gray;">;

</span><span style="color:blue;">DECLARE    </span>@sql_script <span style="color:blue;">NVARCHAR</span><span style="color:gray;">(</span><span style="color:magenta;">MAX</span><span style="color:gray;">)

</span><span style="color:blue;">DECLARE
        </span><span style="color:green;">-- Define user variables.
        </span>@ERR_GENERAL          <span style="color:blue;">INT</span><span style="color:gray;">,
        </span>@ERR_OBJ_NULL          <span style="color:blue;">INT</span><span style="color:gray;">,
        </span>@ErrCode              <span style="color:blue;">INT </span><span style="color:gray;">= </span>0<span style="color:gray;">,
        </span>@ErrMsg               <span style="color:blue;">NVARCHAR</span><span style="color:gray;">(</span>4000<span style="color:gray;">),
        </span>@StepNbr              <span style="color:blue;">SMALLINT </span><span style="color:gray;">= </span>0<span style="color:gray;">,
        </span>@SQL                  <span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:magenta;">MAX</span><span style="color:gray;">);
</span><span style="color:blue;">SET     </span>@ERR_GENERAL          <span style="color:gray;">=</span>99
<span style="color:blue;">SET     </span>@ERR_OBJ_NULL         <span style="color:gray;">=</span>0

<span style="color:blue;">DECLARE </span>@numeridTypes          <span style="color:blue;">TABLE  </span><span style="color:gray;">(</span>datatype <span style="color:blue;">NVARCHAR</span><span style="color:gray;">(</span>255<span style="color:gray;">))
</span><span style="color:blue;">INSERT INTO </span>@numeridTypes
<span style="color:blue;">SELECT </span><span style="color:red;">'INT'
</span><span style="color:blue;">UNION </span><span style="color:gray;">ALL
</span><span style="color:blue;">SELECT </span><span style="color:red;">'FLOAT'

</span><span style="color:blue;">BEGIN
 </span><span style="color:green;">/**
  * STEP 1
  * Set variables.
  */
  </span><span style="color:blue;">SET </span>@StepNbr <span style="color:gray;">+= </span>1<span style="color:gray;">;
  </span><span style="color:blue;">SET </span>@ErrMsg <span style="color:gray;">= </span><span style="color:red;">N'ERROR - Stored procedure [' </span><span style="color:gray;">+ </span><span style="color:magenta;">OBJECT_NAME</span><span style="color:gray;">(</span><span style="color:magenta;">@@PROCID</span><span style="color:gray;">) + </span><span style="color:red;">N'] '</span><span style="color:gray;">;

 </span><span style="color:green;">/**
  * STEP 2
  * CREATE DYNAMIC SQL FOR INSERT
  * MY AUTOMATIC TYPE CHECKING PATTERN FOR SQL
  */
    </span><span style="color:blue;">SELECT
         </span>COLUMN_NAME
        <span style="color:gray;">,</span>DATA_TYPE <span style="color:gray;">=
                </span><span style="color:blue;">CASE WHEN </span>DATA_TYPE <span style="color:gray;">= </span><span style="color:red;">'VARCHAR' </span><span style="color:blue;">THEN </span>DATA_TYPE<span style="color:gray;">+</span><span style="color:red;">'(' </span><span style="color:gray;">+</span><span style="color:magenta;">CAST</span><span style="color:gray;">(</span>CHARACTER_MAXIMUM_LENGTH <span style="color:blue;">AS VARCHAR</span><span style="color:gray;">(</span>5<span style="color:gray;">)) +</span><span style="color:red;">')'
                </span><span style="color:blue;">ELSE </span>DATA_TYPE
        <span style="color:blue;">END
        </span><span style="color:gray;">,</span>IS_NULLABLE
    <span style="color:blue;">INTO </span>#temp_columns
    <span style="color:blue;">FROM </span><span style="color:green;">INFORMATION_SCHEMA</span><span style="color:gray;">.</span><span style="color:green;">COLUMNS </span><span style="color:gray;">(</span><span style="color:blue;">NOLOCK</span><span style="color:gray;">) </span><span style="color:blue;">WHERE </span>TABLE_NAME  <span style="color:gray;">=</span>@stg_typed_table_name 

<span style="color:blue;">IF</span><span style="color:gray;">(</span><span style="color:magenta;">@@ROWCOUNT</span><span style="color:gray;">=</span>0<span style="color:gray;">)
</span><span style="color:blue;">BEGIN
    SET </span>@ErrCode <span style="color:gray;">= </span>@ERR_OBJ_NULL
    <span style="color:blue;">SET </span>@ErrMsg <span style="color:gray;">= </span><span style="color:red;">'TYPED TABLE :'</span><span style="color:gray;">+</span><span style="color:red;">'['</span><span style="color:gray;">+</span>@stg_typed_table_name<span style="color:gray;">+</span><span style="color:red;">']'</span><span style="color:gray;">+</span><span style="color:red;">N'DOES NOT EXISTS'
    </span><span style="color:blue;">GOTO </span>FAIL<span style="color:gray;">;
</span><span style="color:blue;">END

    </span><span style="color:green;">--Flag the records that Fail Data type Validation as INVALID--
    </span><span style="color:blue;">SET </span>@sql_script <span style="color:gray;">= </span><span style="color:red;">N''
    </span><span style="color:blue;">SET </span>@sql_script<span style="color:gray;">= </span>@sql_script<span style="color:gray;">+ </span><span style="color:red;">'UPDATE'</span><span style="color:gray;">+</span><span style="color:red;">'['</span><span style="color:gray;">+ </span>@stg_unTyped_table_name<span style="color:gray;">+</span><span style="color:red;">']'</span><span style="color:gray;">+</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span>13<span style="color:gray;">)
    </span><span style="color:blue;">SET </span>@sql_script<span style="color:gray;">= </span>@sql_script<span style="color:gray;">+ </span><span style="color:red;">'SET'</span><span style="color:gray;">+</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span>9<span style="color:gray;">)+</span>@is_valid_column_name<span style="color:gray;">+</span><span style="color:red;">'=0'</span><span style="color:gray;">+</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span>13<span style="color:gray;">)
    </span><span style="color:blue;">SET </span>@sql_script<span style="color:gray;">= </span>@sql_script<span style="color:gray;">+ </span><span style="color:red;">'WHERE '</span><span style="color:gray;">+</span><span style="color:magenta;">STUFF</span><span style="color:gray;">((</span><span style="color:blue;">SELECT </span><span style="color:red;">'OR '</span><span style="color:gray;">+ </span><span style="color:red;">'1 = CASE WHEN ISNULL(LEN('</span><span style="color:gray;">+</span>COLUMN_NAME<span style="color:gray;">+</span><span style="color:red;">'),0) != 0
    AND ISNUMERIC('</span><span style="color:gray;">+</span>COLUMN_NAME<span style="color:gray;">+</span><span style="color:red;">')= 0 THEN 1 WHEN ISNULL(LEN('</span><span style="color:gray;">+</span>COLUMN_NAME<span style="color:gray;">+</span><span style="color:red;">'),0) = 0    THEN 1    ELSE 0 END  '
    </span><span style="color:blue;">FROM </span>#temp_columns
    <span style="color:blue;">WHERE </span>DATA_TYPE <span style="color:gray;">IN(</span><span style="color:blue;">SELECT </span>datatype <span style="color:blue;">FROM </span>@numeridTypes<span style="color:gray;">) </span><span style="color:blue;">FOR XML PATH</span><span style="color:gray;">(</span><span style="color:red;">''</span><span style="color:gray;">)),</span>1<span style="color:gray;">, </span>3<span style="color:gray;">, </span><span style="color:red;">''</span><span style="color:gray;">)

</span><span style="color:blue;">BEGIN TRY
    IF </span>@i_debugOnly <span style="color:gray;">= </span>1
    <span style="color:blue;">BEGIN
        PRINT </span>@sql_script
    <span style="color:blue;">END
    ELSE
    BEGIN
        EXEC </span><span style="color:maroon;">SP_EXECUTESQL </span>@sql_script
    <span style="color:blue;">END
END TRY
BEGIN CATCH
    IF</span><span style="color:gray;">(</span>@ErrCode <span style="color:gray;">NOT IN (</span>0<span style="color:gray;">,</span>1<span style="color:gray;">))
        </span><span style="color:blue;">SET </span>@ErrCode <span style="color:gray;">= </span>@ERR_GENERAL<span style="color:gray;">;
    </span><span style="color:blue;">SET </span>@ErrMsg <span style="color:gray;">= </span>@ErrMsg <span style="color:gray;">+ </span><span style="color:red;">N'raised error (' </span><span style="color:gray;">+ </span><span style="color:magenta;">CAST</span><span style="color:gray;">(</span><span style="color:magenta;">ERROR_NUMBER</span><span style="color:gray;">() </span><span style="color:blue;">AS NVARCHAR</span><span style="color:gray;">) + </span><span style="color:red;">N') in step number ('
    </span><span style="color:gray;">+ </span><span style="color:magenta;">CAST</span><span style="color:gray;">(</span>@StepNbr <span style="color:blue;">AS NVARCHAR</span><span style="color:gray;">) + </span><span style="color:red;">N') at line number ('
    </span><span style="color:gray;">+ </span><span style="color:magenta;">CAST</span><span style="color:gray;">(</span><span style="color:magenta;">ERROR_LINE</span><span style="color:gray;">() </span><span style="color:blue;">AS NVARCHAR</span><span style="color:gray;">) + </span><span style="color:red;">N') with message: ' </span><span style="color:gray;">+ </span><span style="color:magenta;">ERROR_MESSAGE</span><span style="color:gray;">() ;
    </span><span style="color:blue;">GOTO </span>FAIL<span style="color:gray;">;
</span><span style="color:blue;">END CATCH</span><span style="color:gray;">;

    </span><span style="color:green;">--INSERT THE GOOD ONES IN typed--
    --If the Untyped is added with a IS_VALID column then the below SQL can be optimized to JUST a simple SELECT WHERE IS_VALID = 1--
    </span><span style="color:blue;">SET </span>@sql_script <span style="color:gray;">= </span><span style="color:red;">N''
    </span><span style="color:blue;">SET </span>@sql_script<span style="color:gray;">= </span>@sql_script<span style="color:gray;">+ </span><span style="color:red;">'INSERT INTO'</span><span style="color:gray;">+</span><span style="color:red;">'['</span><span style="color:gray;">+ </span>@stg_typed_table_name<span style="color:gray;">+</span><span style="color:red;">']'</span><span style="color:gray;">+</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span>13<span style="color:gray;">)
    </span><span style="color:blue;">SET </span>@sql_script<span style="color:gray;">= </span>@sql_script<span style="color:gray;">+ </span><span style="color:red;">'SELECT'</span><span style="color:gray;">+</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span>13<span style="color:gray;">)
    </span><span style="color:blue;">SET </span>@sql_script<span style="color:gray;">= </span>@sql_script<span style="color:gray;">+ </span><span style="color:magenta;">STUFF</span><span style="color:gray;">((</span><span style="color:blue;">SELECT </span><span style="color:red;">', ' </span><span style="color:gray;">+ </span><span style="color:red;">'['</span><span style="color:gray;">+</span>COLUMN_NAME<span style="color:gray;">+</span><span style="color:red;">']' </span><span style="color:blue;">FROM </span>#temp_columns <span style="color:blue;">FOR XML PATH</span><span style="color:gray;">(</span><span style="color:red;">''</span><span style="color:gray;">)),</span>1<span style="color:gray;">, </span>2<span style="color:gray;">, </span><span style="color:red;">''</span><span style="color:gray;">)
                     +</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span>13<span style="color:gray;">)
    </span><span style="color:blue;">SET </span>@sql_script<span style="color:gray;">= </span>@sql_script<span style="color:gray;">+ </span><span style="color:red;">'FROM'</span><span style="color:gray;">+</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span>9<span style="color:gray;">)+</span><span style="color:red;">'['</span><span style="color:gray;">+</span>@stg_unTyped_table_name<span style="color:gray;">+</span><span style="color:red;">']'</span><span style="color:gray;">+</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span>13<span style="color:gray;">)
    </span><span style="color:blue;">SET </span>@sql_script<span style="color:gray;">= </span>@sql_script<span style="color:gray;">+ </span><span style="color:red;">'WHERE '</span><span style="color:gray;">+</span><span style="color:magenta;">STUFF</span><span style="color:gray;">((</span><span style="color:blue;">SELECT </span><span style="color:red;">'AND '</span><span style="color:gray;">+ </span><span style="color:red;">'1 = CASE WHEN ISNULL(LEN('</span><span style="color:gray;">+</span>COLUMN_NAME<span style="color:gray;">+</span><span style="color:red;">'),0) != 0
                     AND ISNUMERIC('</span><span style="color:gray;">+</span>COLUMN_NAME<span style="color:gray;">+</span><span style="color:red;">')= 1 THEN 1 WHEN ISNULL(LEN('</span><span style="color:gray;">+</span>COLUMN_NAME<span style="color:gray;">+</span><span style="color:red;">'),0) = 0    THEN 1    ELSE 0 END  '
                     </span><span style="color:blue;">FROM </span>#temp_columns
                     <span style="color:blue;">WHERE </span>DATA_TYPE <span style="color:gray;">IN(</span><span style="color:blue;">SELECT </span>datatype <span style="color:blue;">FROM </span>@numeridTypes<span style="color:gray;">) </span><span style="color:blue;">FOR XML PATH</span><span style="color:gray;">(</span><span style="color:red;">''</span><span style="color:gray;">)),</span>1<span style="color:gray;">, </span>3<span style="color:gray;">, </span><span style="color:red;">''</span><span style="color:gray;">)

</span><span style="color:blue;">BEGIN TRY
    IF </span>@i_debugOnly <span style="color:gray;">= </span>1
    <span style="color:blue;">BEGIN
        PRINT </span>@sql_script
    <span style="color:blue;">END
    ELSE
    BEGIN
        EXEC </span><span style="color:maroon;">SP_EXECUTESQL </span>@sql_script
    <span style="color:blue;">END
END TRY
BEGIN CATCH
    IF</span><span style="color:gray;">(</span>@ErrCode <span style="color:gray;">NOT IN (</span>0<span style="color:gray;">,</span>1<span style="color:gray;">))
        </span><span style="color:blue;">SET </span>@ErrCode <span style="color:gray;">= </span>@ERR_GENERAL<span style="color:gray;">;
    </span><span style="color:blue;">SET </span>@ErrMsg <span style="color:gray;">= </span>@ErrMsg <span style="color:gray;">+ </span><span style="color:red;">N'raised error (' </span><span style="color:gray;">+ </span><span style="color:magenta;">CAST</span><span style="color:gray;">(</span><span style="color:magenta;">ERROR_NUMBER</span><span style="color:gray;">() </span><span style="color:blue;">AS NVARCHAR</span><span style="color:gray;">) + </span><span style="color:red;">N')
    in step number (' </span><span style="color:gray;">+ </span><span style="color:magenta;">CAST</span><span style="color:gray;">(</span>@StepNbr <span style="color:blue;">AS NVARCHAR</span><span style="color:gray;">) + </span><span style="color:red;">N') at line number ('
                 </span><span style="color:gray;">+ </span><span style="color:magenta;">CAST</span><span style="color:gray;">(</span><span style="color:magenta;">ERROR_LINE</span><span style="color:gray;">() </span><span style="color:blue;">AS NVARCHAR</span><span style="color:gray;">) + </span><span style="color:red;">N') with message: ' </span><span style="color:gray;">+ </span><span style="color:magenta;">ERROR_MESSAGE</span><span style="color:gray;">() ;
    </span><span style="color:blue;">GOTO </span>FAIL<span style="color:gray;">;
</span><span style="color:blue;">END CATCH</span><span style="color:gray;">;

</span><span style="color:blue;">GOTO </span>SUCCESS<span style="color:gray;">;

</span><span style="color:blue;">FAIL:
  RAISERROR</span><span style="color:gray;">(</span>@ErrMsg<span style="color:gray;">, </span>16<span style="color:gray;">, </span>1<span style="color:gray;">);
  </span><span style="color:blue;">RETURN </span>@ErrCode<span style="color:gray;">;

</span><span style="color:blue;">SUCCESS:
  </span><span style="color:green;">-- Commit the transaction.
  </span><span style="color:blue;">RETURN </span>0<span style="color:gray;">;

</span><span style="color:blue;">DROP TABLE </span>#temp_columns
<span style="color:blue;">END</span><span style="color:gray;">;</span></pre>
<pre class="code"><span style="color:gray;">
</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p style="line-height:normal;margin-bottom:16.2pt;background:white;" class="MsoNormal"><a href="//\\Now"><span style="font-family:consolas;color:#444444;font-size:12pt;"><font size="2" face="verd">Now</font></span><font size="2" face="verd"> when you run this SP in DEBUG MODE as show in the example in the SP code itself</font></a></p>
<p style="line-height:normal;margin-bottom:16.2pt;background:white;" class="MsoNormal"><span style="font-family:consolas;color:#444444;font-size:12pt;"><font size="2" face="verd">It will print out the SQL that it generated. Setting debug_only to 0 will run this. The SQL generated is like</font></span></p>
<pre class="code"><span style="color:blue;">UPDATE</span>[untyped]
<span style="color:blue;">SET    </span>IS_VALID<span style="color:gray;">=</span>0
<span style="color:blue;">WHERE </span>1 <span style="color:gray;">= </span><span style="color:blue;">CASE WHEN </span><span style="color:magenta;">ISNULL</span><span style="color:gray;">(</span><span style="color:magenta;">LEN</span><span style="color:gray;">(</span>ID<span style="color:gray;">),</span>0<span style="color:gray;">) != </span>0 <span style="color:gray;">AND </span><span style="color:magenta;">ISNUMERIC</span><span style="color:gray;">(</span>ID<span style="color:gray;">)= </span>0 <span style="color:blue;">THEN </span>1 <span style="color:blue;">WHEN </span><span style="color:magenta;">ISNULL</span><span style="color:gray;">(</span><span style="color:magenta;">LEN</span><span style="color:gray;">(</span>ID<span style="color:gray;">),</span>0<span style="color:gray;">) = </span>0
<span style="color:blue;">THEN </span>1    <span style="color:blue;">ELSE </span>0 <span style="color:blue;">END  </span><span style="color:gray;">OR </span>1 <span style="color:gray;">= </span><span style="color:blue;">CASE WHEN </span><span style="color:magenta;">ISNULL</span><span style="color:gray;">(</span><span style="color:magenta;">LEN</span><span style="color:gray;">(</span>SALARY<span style="color:gray;">),</span>0<span style="color:gray;">) != </span>0 <span style="color:gray;">AND </span><span style="color:magenta;">ISNUMERIC</span><span style="color:gray;">(</span>SALARY<span style="color:gray;">)= </span>0 <span style="color:blue;">THEN </span>1
<span style="color:blue;">WHEN </span><span style="color:magenta;">ISNULL</span><span style="color:gray;">(</span><span style="color:magenta;">LEN</span><span style="color:gray;">(</span>SALARY<span style="color:gray;">),</span>0<span style="color:gray;">) = </span>0    <span style="color:blue;">THEN </span>1    <span style="color:blue;">ELSE </span>0 <span style="color:blue;">END  

INSERT INTO</span>[typed]
<span style="color:blue;">SELECT
</span>[ID]<span style="color:gray;">, </span>[TITLE]<span style="color:gray;">, </span>[NAME]<span style="color:gray;">, </span>[SALARY]
<span style="color:blue;">FROM    </span>[untyped]
<span style="color:blue;">WHERE  </span>1 <span style="color:gray;">= </span><span style="color:blue;">CASE WHEN </span><span style="color:magenta;">ISNULL</span><span style="color:gray;">(</span><span style="color:magenta;">LEN</span><span style="color:gray;">(</span>ID<span style="color:gray;">),</span>0<span style="color:gray;">) != </span>0 <span style="color:gray;">AND </span><span style="color:magenta;">ISNUMERIC</span><span style="color:gray;">(</span>ID<span style="color:gray;">)= </span>1 <span style="color:blue;">THEN </span>1 <span style="color:blue;">WHEN </span><span style="color:magenta;">ISNULL</span><span style="color:gray;">(</span><span style="color:magenta;">LEN</span><span style="color:gray;">(</span>ID<span style="color:gray;">),</span>0<span style="color:gray;">) = </span>0    <span style="color:blue;">THEN </span>1
<span style="color:blue;">ELSE </span>0 <span style="color:blue;">END
</span><span style="color:gray;">AND </span>1 <span style="color:gray;">= </span><span style="color:blue;">CASE WHEN </span><span style="color:magenta;">ISNULL</span><span style="color:gray;">(</span><span style="color:magenta;">LEN</span><span style="color:gray;">(</span>SALARY<span style="color:gray;">),</span>0<span style="color:gray;">) != </span>0 <span style="color:gray;">AND </span><span style="color:magenta;">ISNUMERIC</span><span style="color:gray;">(</span>SALARY<span style="color:gray;">)= </span>1 <span style="color:blue;">THEN </span>1 <span style="color:blue;">WHEN </span><span style="color:magenta;">ISNULL</span><span style="color:gray;">(</span><span style="color:magenta;">LEN</span><span style="color:gray;">(</span>SALARY<span style="color:gray;">),</span>0<span style="color:gray;">) = </span>0    <span style="color:blue;">THEN </span>1
<span style="color:blue;">ELSE </span>0 <span style="color:blue;">END
</span></pre>
<p><a href="http://11011.net/software/vspaste"></a><span style="font-family:consolas;color:#444444;font-size:12pt;"></p>
<p></span></p>
<p style="line-height:normal;margin-bottom:16.2pt;background:white;" class="MsoNormal"><span style="font-family:consolas;color:#444444;font-size:12pt;"><font size="2" face="ver">You can see how using dynamic SQL and Information schemas a nice Type check is generated and another </font></span></p>
<p style="line-height:normal;margin-bottom:16.2pt;background:white;" class="MsoNormal"><span style="font-family:consolas;color:#444444;font-size:12pt;"><font size="2" face="ver">UPDATE to set the validation column = 0 is also created. Best Part is table names and Validation Column names and ISNUMRIC validation types all are configurable. </font></span></p>
<p><font size="2" face="ver"></font></p>
</p>
<p><font face="ver"></font></p>
<p style="line-height:normal;margin-bottom:16.2pt;background:white;" class="MsoNormal"><span style="font-family:consolas;color:#444444;font-size:12pt;"><font size="2" face="ver">Now I will run the query with Debug flag = 0 and you would see that the output is as expected. Out of 9 ROWS 7 Will be loaded in Typed Tabled and 2 Will be marked as invalid in the untyped table. </font></span></p>
<p><font size="2" face="ver"></font></p>
</p>
<p><font face="ver"></font></p>
<p style="line-height:normal;margin-bottom:16.2pt;background:white;" class="MsoNormal"><a href="\Users\Ashwani.Roy\AppData\Local\Temp\WindowsLiveWriter1286139640\supfiles20FE865\image%5b3%5d.png"><span style="font-family:consolas;color:#0066a7;font-size:12pt;text-decoration:none;"><span><font color="#444444" size="2" face="ver"><img style="display:inline;border-width:0;" title="clip_image002" border="0" alt="clip_image002" src="http://sqlkit.files.wordpress.com/2010/04/clip_image002.png?w=534&#038;h=437" width="534" height="437" /></font></span></span></a><span style="font-family:consolas;color:#444444;font-size:12pt;"><font size="2" face="ver">&#160; </font></span></p>
<p><font size="2" face="ver"></font></p>
</p>
<p><font face="ver"></font></p>
<p style="line-height:normal;margin-bottom:16.2pt;background:white;" class="MsoNormal"><span style="font-family:consolas;color:#444444;font-size:12pt;"><font size="2" face="ver">There you go. Job Done. </font></span></p>
<p><font size="2" face="ver"></font></p>
</p>
<p><font face="ver"></font></p>
<p style="line-height:normal;margin-bottom:16.2pt;background:white;" class="MsoNormal"><span style="font-family:consolas;color:#444444;font-size:12pt;"><font size="2" face="ver">Hope you find it useful and will be able to extend to do more validation , checks and Error Redirect type stuff using one SP making you life a little easier. </font></span></p>
<p><font size="2" face="ver"></font></p>
</p>
<p><font face="ver"></font></p>
<p style="line-height:normal;margin-bottom:16.2pt;background:white;" class="MsoNormal"><span style="font-family:consolas;color:#444444;font-size:12pt;">&#160; </span></p>
</p>
</p>
<p class="MsoNormal"><span style="font-family:consolas;"></span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlkit.wordpress.com/104/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlkit.wordpress.com/104/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlkit.wordpress.com/104/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlkit.wordpress.com/104/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlkit.wordpress.com/104/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlkit.wordpress.com/104/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlkit.wordpress.com/104/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlkit.wordpress.com/104/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlkit.wordpress.com/104/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlkit.wordpress.com/104/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlkit.wordpress.com/104/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlkit.wordpress.com/104/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlkit.wordpress.com/104/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlkit.wordpress.com/104/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkit.com&amp;blog=6555210&amp;post=104&amp;subd=sqlkit&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlkit.com/2010/04/11/a-generic-untyped-to-typed-table-load-which-does-automatic-type-checking-and-error-redirection-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">ashwaniroy</media:title>
		</media:content>

		<media:content url="http://sqlkit.files.wordpress.com/2010/04/clip_image0011.jpg" medium="image">
			<media:title type="html">clip_image001</media:title>
		</media:content>

		<media:content url="http://sqlkit.files.wordpress.com/2010/04/clip_image002.png" medium="image">
			<media:title type="html">clip_image002</media:title>
		</media:content>
	</item>
		<item>
		<title>Inside SQL Server 2008 &#8211; Get 40 % Off</title>
		<link>http://sqlkit.com/2010/03/25/inside-sql-server-2008-get-40-off/</link>
		<comments>http://sqlkit.com/2010/03/25/inside-sql-server-2008-get-40-off/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 15:18:14 +0000</pubDate>
		<dc:creator>ashwaniroy</dc:creator>
				<category><![CDATA[SQL Server 2008]]></category>

		<guid isPermaLink="false">http://sqlkit.wordpress.com/2010/03/25/inside-sql-server-2008-get-40-off/</guid>
		<description><![CDATA[Since I am doing a book review for this book , readers of my blog are also more than welcome use promo code to get a discount of 40% against that book at www.microsoft-press.co.uk. Readers can enter the code: MVPT894 at the checkout when they purchase before the end of April 2010. Inside Microsoft SQL [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkit.com&amp;blog=6555210&amp;post=98&amp;subd=sqlkit&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Since I am doing a book review for this book , readers of my blog are also more than welcome use promo code to get a discount of 40% against that book at <a href="http://www.microsoft-press.co.uk">www.microsoft-press.co.uk</a>. Readers can enter the code: MVPT894 at the checkout when they purchase before the end of April 2010.</p>
<p><img alt="9780735626034x" src="http://blogs.msdn.com/blogfiles/microsoft_press/WindowsLiveWriter/InsideMicrosoftSQLServer2008TSQLQuerying_8E7C/9780735626034x_thumb.jpg" /></p>
<p><em><a href="http://www.amazon.com/Inside-Microsoft%C2%AE-Server%C2%AE-2008-Pro-Developer/dp/0735626030/ref=pd_bbs_sr_2?ie=UTF8&amp;s=books&amp;qid=1235671837&amp;sr=8-2">Inside Microsoft SQL Server 2008: T-SQL Querying</a></em> (Microsoft Press, 2009), by Itzik Ben-Gan, Lubor Kollar, Dejan Sarka, and Steve Kass, is an update of <em><a href="http://www.amazon.com/Inside-Microsoft-SQL-Server-2005/dp/0735623139/ref=pd_bbs_sr_1?ie=UTF8&amp;s=books&amp;qid=1235671478&amp;sr=8-1">Inside Microsoft SQL Server 2005: T-SQL Querying</a></em>, which, you can see by its 29 Amazon reviews (most of them 5 stars), is a very effective and popular SQL Server book.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlkit.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlkit.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlkit.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlkit.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlkit.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlkit.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlkit.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlkit.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlkit.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlkit.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlkit.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlkit.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlkit.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlkit.wordpress.com/98/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkit.com&amp;blog=6555210&amp;post=98&amp;subd=sqlkit&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlkit.com/2010/03/25/inside-sql-server-2008-get-40-off/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">ashwaniroy</media:title>
		</media:content>

		<media:content url="http://blogs.msdn.com/blogfiles/microsoft_press/WindowsLiveWriter/InsideMicrosoftSQLServer2008TSQLQuerying_8E7C/9780735626034x_thumb.jpg" medium="image">
			<media:title type="html">9780735626034x</media:title>
		</media:content>
	</item>
		<item>
		<title>Writing Test Cases for Database Queries and Stored Procedure using VS 2010</title>
		<link>http://sqlkit.com/2009/12/19/writing-test-cases-for-database-queries-and-stored-procedure-using-vs-2010/</link>
		<comments>http://sqlkit.com/2009/12/19/writing-test-cases-for-database-queries-and-stored-procedure-using-vs-2010/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 03:04:43 +0000</pubDate>
		<dc:creator>ashwaniroy</dc:creator>
				<category><![CDATA[SQL Server 2008]]></category>

		<guid isPermaLink="false">http://sqlkit.wordpress.com/2009/12/19/writing-test-cases-for-database-queries-and-stored-procedure-using-vs-2010/</guid>
		<description><![CDATA[I was playing around with a recently downloaded Beta 2 of VS 2010. As of me , I work a lot with Databases and Data warehouses but I did have an opportunity to work with C# based development using ADO.NET entity framework sometime back. I am a big fan or writing test cases and making [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkit.com&amp;blog=6555210&amp;post=88&amp;subd=sqlkit&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was playing around with a recently downloaded Beta 2 of VS 2010. As of me , I work a lot with Databases and Data warehouses but I did have an opportunity to work with C# based development using ADO.NET entity framework sometime back. </p>
<p>I am a big fan or writing test cases and making sure that I achieve a good code coverage. With VS 2010 I can write test cases for database objects like stored procedures. In this blog post I am going to write a very small bit about how you can write test cases for SQL Queries using VS 2010. (You don’t need any NUnit or csUnit as you might need in previous versions of VS and even in that case I don’t see an easy way as VS 2010 provides). </p>
<p>Start VS 2010 and go to ribbon on the top</p>
<p><a href="http://sqlkit.files.wordpress.com/2009/12/image.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://sqlkit.files.wordpress.com/2009/12/image_thumb.png?w=594&#038;h=100" width="594" height="100" /></a> </p>
<p>Click New Test and select Database Unit Test</p>
<p><a href="http://sqlkit.files.wordpress.com/2009/12/image1.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://sqlkit.files.wordpress.com/2009/12/image_thumb1.png?w=439&#038;h=365" width="439" height="365" /></a> </p>
<p>Configure the database connection string and Project name and other stuff</p>
<p><a href="http://sqlkit.files.wordpress.com/2009/12/image2.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://sqlkit.files.wordpress.com/2009/12/image_thumb2.png?w=552&#038;h=333" width="552" height="333" /></a> </p>
<p>&#160;</p>
<p>You will have a window which will look like this. Click on the CREATE NEW link</p>
<p><a href="http://sqlkit.files.wordpress.com/2009/12/image3.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://sqlkit.files.wordpress.com/2009/12/image_thumb3.png?w=644&#038;h=391" width="644" height="391" /></a> </p>
<p>&#160;</p>
<p>You can my TestMyProc.cs . This is a C# class. You can Paste you SQL code in the designer and the C# class will wrap this and execute it using ADO.NET . You need not worry writing the TESTFIXTURES and etc etc</p>
<p>The designer has this commented bit on top which is self explanatory.</p>
<p>/*    <br />Add T-SQL statements here to exercise the database object     <br />that you want to test. </p>
<p>To test a stored procedure, invoke it here by adding    <br />an EXEC statement that has appropriate parameters. </p>
<p>In the lower pane, you can add test conditions that verify    <br />whether the results of your T-SQL statements match what     <br />you expect.     <br />*/</p>
<p>Ok . Now lest write some test . Lets Begin with a negative on. Which Will fail.</p>
<p>I have configured my Database to connect to adventureworks. </p>
<p>The SQL Code I want to test is </p>
<pre class="code"><span style="color:blue;">SELECT </span><span style="color:gray;">* </span><span style="color:blue;">FROM </span><span style="color:teal;">HumanResources</span><span style="color:gray;">.</span><span style="color:teal;">Employee   </span><span style="color:blue;">WHERE </span><span style="color:teal;">BusinessEntityID  </span><span style="color:gray;">= </span><span style="color:brown;">1 </span><span style="color:green;">--will fail
</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Now go down to test condition panel. Here you can specify the conditions which will be based on what is the expected output. So Lets say I don’t expect any result set. </p>
<p><a href="http://sqlkit.files.wordpress.com/2009/12/image4.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://sqlkit.files.wordpress.com/2009/12/image_thumb4.png?w=547&#038;h=122" width="547" height="122" /></a> </p>
<p>After you have configured the Condition you need to run this test. </p>
<p><a href="http://sqlkit.files.wordpress.com/2009/12/image5.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://sqlkit.files.wordpress.com/2009/12/image_thumb5.png?w=486&#038;h=285" width="486" height="285" /></a> </p>
<p>The test result panel will have the below output stating that test has failed.</p>
<p><a href="http://sqlkit.files.wordpress.com/2009/12/image6.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://sqlkit.files.wordpress.com/2009/12/image_thumb6.png?w=477&#038;h=134" width="477" height="134" /></a> </p>
<p>Now change the SQL Query to </p>
<pre class="code"><span style="color:blue;">SELECT </span><span style="color:gray;">* </span><span style="color:blue;">FROM </span><span style="color:teal;">HumanResources</span><span style="color:gray;">.</span><span style="color:teal;">Employee   </span><span style="color:blue;">WHERE </span><span style="color:teal;">BusinessEntityID  </span><span style="color:gray;">= -</span><span style="color:brown;">1 </span><span style="color:green;">--will succeed
</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>and run the test again. The test result panel will show PASSED</p>
<p><a href="http://sqlkit.files.wordpress.com/2009/12/image7.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://sqlkit.files.wordpress.com/2009/12/image_thumb7.png?w=535&#038;h=139" width="535" height="139" /></a> </p>
<p>So we have written our first Unit Test to Test a SQL Query. The same thing can be extended to Stored Procedures. I don’t know as of now if it supports MDX unit testing out of the box but if go the code behind (F7) you will see a C# class. You can add ADOMD or AMO and test MDX , XMLA or anything else in theory. I have not tried it yet though.</p>
<p>Happy Test Driven Development for Database Guys!!. I will be blogging more on this.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlkit.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlkit.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlkit.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlkit.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlkit.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlkit.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlkit.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlkit.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlkit.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlkit.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlkit.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlkit.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlkit.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlkit.wordpress.com/88/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkit.com&amp;blog=6555210&amp;post=88&amp;subd=sqlkit&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlkit.com/2009/12/19/writing-test-cases-for-database-queries-and-stored-procedure-using-vs-2010/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">ashwaniroy</media:title>
		</media:content>

		<media:content url="http://sqlkit.files.wordpress.com/2009/12/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://sqlkit.files.wordpress.com/2009/12/image_thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://sqlkit.files.wordpress.com/2009/12/image_thumb2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://sqlkit.files.wordpress.com/2009/12/image_thumb3.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://sqlkit.files.wordpress.com/2009/12/image_thumb4.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://sqlkit.files.wordpress.com/2009/12/image_thumb5.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://sqlkit.files.wordpress.com/2009/12/image_thumb6.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://sqlkit.files.wordpress.com/2009/12/image_thumb7.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Microsoft MVP Award to Me !! Thank you all</title>
		<link>http://sqlkit.com/2009/10/02/microsoft-mvp-award-to-me-thank-you-all/</link>
		<comments>http://sqlkit.com/2009/10/02/microsoft-mvp-award-to-me-thank-you-all/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 00:17:25 +0000</pubDate>
		<dc:creator>ashwaniroy</dc:creator>
				<category><![CDATA[SQL Server 2008]]></category>

		<guid isPermaLink="false">http://sqlkit.wordpress.com/2009/10/02/microsoft-mvp-award-to-me-thank-you-all/</guid>
		<description><![CDATA[I got a email today at 4:00 PM from Microsoft MVP award which read Dear Ashwani Roy, Congratulations! We are pleased to present you with the 2009 Microsoft® MVP Award! This award is given to exceptional technical community leaders who actively share their high quality, real world expertise with others. We appreciate your outstanding contributions [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkit.com&amp;blog=6555210&amp;post=71&amp;subd=sqlkit&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I got a email today at 4:00 PM from Microsoft MVP award which read</p>
<blockquote><p><em>Dear Ashwani Roy,        <br />Congratulations! We are pleased to present you with the 2009 Microsoft® MVP Award! This award is given to exceptional technical community leaders who actively share their high quality, real world expertise with others. We appreciate your outstanding contributions in SQL Server technical communities during the past year</em></p>
</blockquote>
<p>I would like to thank UK SQL Server Community , my blog readers my peers and friends and I hope I will keep adding value to community.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlkit.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlkit.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlkit.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlkit.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlkit.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlkit.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlkit.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlkit.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlkit.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlkit.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlkit.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlkit.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlkit.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlkit.wordpress.com/71/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkit.com&amp;blog=6555210&amp;post=71&amp;subd=sqlkit&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlkit.com/2009/10/02/microsoft-mvp-award-to-me-thank-you-all/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">ashwaniroy</media:title>
		</media:content>
	</item>
	</channel>
</rss>
