<?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>Rafi Asraf SQL Server Blog</title>
	<atom:link href="http://sqlserverjedi.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://sqlserverjedi.wordpress.com</link>
	<description>&#34;A common mistake people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.&#34; Douglas Adams (1952 - 2001), &#34;Mostly Harmless&#34;</description>
	<lastBuildDate>Tue, 21 Feb 2012 15:26:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='sqlserverjedi.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Rafi Asraf SQL Server Blog</title>
		<link>http://sqlserverjedi.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://sqlserverjedi.wordpress.com/osd.xml" title="Rafi Asraf SQL Server Blog" />
	<atom:link rel='hub' href='http://sqlserverjedi.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Loading SAS files with SSIS</title>
		<link>http://sqlserverjedi.wordpress.com/2012/02/08/loading-sas-files-with-ssis/</link>
		<comments>http://sqlserverjedi.wordpress.com/2012/02/08/loading-sas-files-with-ssis/#comments</comments>
		<pubDate>Wed, 08 Feb 2012 16:50:30 +0000</pubDate>
		<dc:creator>sirpadk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[SAS Institute]]></category>
		<category><![CDATA[SSIS]]></category>

		<guid isPermaLink="false">http://sqlserverjedi.wordpress.com/?p=146</guid>
		<description><![CDATA[Hi I&#8217;ve been given an assignment to load data from a SAS Institute data file to SQL Server using SSIS. How hard can that be I thought to my self. All I needed to do was to find the oledb provider for SAS, install it on my machine, and use it within SSIS, a no brainer! Well [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlserverjedi.wordpress.com&amp;blog=28511675&amp;post=146&amp;subd=sqlserverjedi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hi</p>
<p>I&#8217;ve been given an assignment to load data from a <a class="zem_slink" title="SAS Institute" href="http://en.wikipedia.org/wiki/SAS_Institute" rel="wikipedia">SAS Institute</a> data file to SQL Server using SSIS. How hard can that be I thought to my self. All I needed to do was to find the oledb provider for SAS, install it on my machine, and use it within SSIS, a no brainer!</p>
<p>Well first it took some time for me to actually find the oledb provider. You see SAS Institute provide it for free, which is great, but they kinda keep it in a secret place. If you google &#8220;<a href="http://www.google.dk/search?gcx=w&amp;sourceid=chrome&amp;ie=UTF-8&amp;q=sas+oledb+provider" target="_blank">sas oledb provider</a>&#8221; the first result is <a href="http://support.sas.com/documentation/tools/oledb/" target="_blank">this</a>, which is a general documation spot for the SAS Oledb Provider, which is a great source for content regarding how to use the provider, but where to download it? Well you need to click on some links, only to get to a page that tells you where you can download it, but guess what, the part that tells you where to download it from is NOT a link, it&#8217;s URL indeed, but it&#8217;s not marked as a link, and very hard to find in all the other text on the page. Unfortunately I&#8217;m not a reader, I&#8217;m a scanner (we&#8217;ll get back to that later also). When I need to read something fast, which is almost always, I scan the text looking for known patterns instead of actually reading the entire content. So when I look for a link for downloading the file, I tend to not read any irrelevant text, which in this case was the link, disguising as normal text. But I&#8217;m a good person, so I&#8217;ll help you guys with that, here is the direct link to the <a href="http://support.sas.com/demosdownloads/setupcat.jsp?cat=SAS+Providers+for+OLE+DB" target="_blank">download page</a>, if you need to download it. You&#8217;ll need to register and confirm by an email first.</p>
<p>Now that I got the provider, I opened SSIS and did the following:</p>
<ol>
<li>Created anew connection manager to my SAS file using the &#8220;Native OLE DB\SAS Local Data Provider 9.3&#8243;</li>
<li>In the Server or FileName I wrote the full path of the file name (which we&#8217;ll later go back to)</li>
<li>Pressing Test Connection to make sure it works and pressed OK</li>
<li>Added a new OLE DB Source to my data flow task</li>
<li>In the OLE DB Source Editor I tried to pick the table in the SAS file, only to get an error message with the following content: &#8220;fn =ydedopn; context =sasej9lib.dll.&#8221;</li>
</ol>
<p>So I thought I&#8217;ll google that, and guess what, one result only, to a linked in post of a guy asking for help with the same problem, no one with a solution.</p>
<p>I thought well let&#8217;s try and isolate the issue, so I started windows console project, to test to connectivity logic using an OleDb provider to the SAS file. I&#8217;ve spent 2 hours on this, trying with all kind of different ways to make it work, but either I got an empty data table, or the same error message as in SSIS. Frustrated I kept on going back and forward between the SAS website documentation, looking for a hint, and there, just before I was to give up, I saw the problem!</p>
<p>In the documentation it states that the datasource property is &#8220;A physical directory that contains the SAS data set that you want to access with the connection.&#8221; How did I missed that? (damn you scanners!) I shouldn&#8217;t have used the file name, but the file directory! The provider treats the folder as the &#8220;database&#8221; and each file is a &#8220;table&#8221; in the &#8220;database&#8221;!</p>
<p>Changing that simple fact, I was able to select a table from the Ole Db Source Editor, and beside some page code warnings which I&#8217;ll look into later, everything works as is should.</p>
<p>So the conclusions are:</p>
<ul>
<li>don&#8217;t scan the documentation, read it! (this conclusion is pointed to me only)</li>
<li>when pointing to a SAS Institute files use only the directory in the data source!</li>
</ul>
<p>I hope this will help others</p>
<p>/Rafi</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlserverjedi.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlserverjedi.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlserverjedi.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlserverjedi.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlserverjedi.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlserverjedi.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlserverjedi.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlserverjedi.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlserverjedi.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlserverjedi.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlserverjedi.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlserverjedi.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlserverjedi.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlserverjedi.wordpress.com/146/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlserverjedi.wordpress.com&amp;blog=28511675&amp;post=146&amp;subd=sqlserverjedi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlserverjedi.wordpress.com/2012/02/08/loading-sas-files-with-ssis/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e5a38ef3957aede031fbf94c2c6ec260?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sirpadk</media:title>
		</media:content>
	</item>
		<item>
		<title>Catch Custom Events with SSIS Event Handler</title>
		<link>http://sqlserverjedi.wordpress.com/2012/01/05/catch-custom-events-with-ssis-event-handler/</link>
		<comments>http://sqlserverjedi.wordpress.com/2012/01/05/catch-custom-events-with-ssis-event-handler/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 16:23:10 +0000</pubDate>
		<dc:creator>sirpadk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://sqlserverjedi.wordpress.com/?p=141</guid>
		<description><![CDATA[Background When I started working for PensionDanmark summer 2011, we started looking into using SSIS as the main ETL tool for the Datawarehouse team. One of the main requirements were to be able to bring SSIS into the enterprise scale, and to be able to design and implement a pattern that will be able to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlserverjedi.wordpress.com&amp;blog=28511675&amp;post=141&amp;subd=sqlserverjedi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Background</strong></p>
<p>When I started working for PensionDanmark summer 2011, we started looking into using SSIS as the main ETL tool for the Datawarehouse team. One of the main requirements were to be able to bring SSIS into the enterprise scale, and to be able to design and implement a pattern that will be able to cover a wide range of ETL related tasks though out the enterprise.</p>
<p>I knew that SSIS is lacking some of these enterprise needs, and when I saw Andy Leonard approach using a framework, I decided to try and implement one similar in PensionDanmark. What really got my attention was the ability to have a meta data driven approach to the execution of SSIS, and the ability to centralize the settings of logging, and by that to allow multiple child package to be simple and yet to inherit a complex set of events logging, that can be maintained easily, without effecting the child packages.</p>
<p>After the implementation of the first version of the framework, we had a request from the users to be able to report on non standard events. I thought that it should be quite simple, as SSIS has a custom event, and SSIS Script Task Component has the ability to fire custom events. But I was wrong to think it was that simple, because the SSIS event handler has no implementation for the custom event.</p>
<p>The problem description is like this: the frameworks central logging feature is build on the fact that the event handlers of the parent package (the framework package) is able to catch events that are fired in the child package too. But there is no event handler for the custom event, so what can we do?</p>
<p><strong>A Solution</strong></p>
<p>What we need is a workaround, that will allow us to catch a custom event, fired in the child package, using an event handler of the parent package. I started to look into the types of events which have an event handler, and to see weather I could hijack one, and make it act as a custom event handler, and than I saw it, the perfect victim for the task,  the <em>VariableChanged </em>event handler!</p>
<p>Why is it perfect?</p>
<ul>
<li>I&#8217;ve never used it in production in my years developing SSIS packages.</li>
<li>The event is fully controlled by the developer. That is the SSIS developer chooses to enable this event on a variable. This is something we cannot do with any other event!</li>
<li>I believe that it&#8217;s by far a event that one is willing to live without for the price of having custom event in a centralize manner. I know I would <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> .</li>
</ul>
<p>Let&#8217;s take a look on how we actually doing it:</p>
<p>Here is the parent package, it’s made simple, in order to better illustrate the event catch scenario. An SSIS Framework looks of course more complex than this simple parent package.</p>
<p><a href="http://sqlserverjedi.files.wordpress.com/2012/01/image.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="The parent package" src="http://sqlserverjedi.files.wordpress.com/2012/01/image_thumb.png?w=600&#038;h=679" alt="The parent package" width="600" height="679" border="0" /></a></p>
<p>&nbsp;</p>
<p>The parent package has a script component in the OnVariableValueChanged. With that script we will need to catch the variables which are available for this type of event, and use them to log the real event that is fired by the child package.</p>
<p><a href="http://sqlserverjedi.files.wordpress.com/2012/01/image1.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="The Parent Package Event Handler" src="http://sqlserverjedi.files.wordpress.com/2012/01/image_thumb1.png?w=602&#038;h=691" alt="The Parent Package Event Handler" width="602" height="691" border="0" /></a></p>
<p>This is how the script looks like:</p>
<pre class="csharpcode"><span class="rem">'The follwing variables are accesable from this type of event handler:</span>
<span class="rem">'System::TaskName</span>
<span class="rem">'System::SourceName</span>
<span class="rem">'System::VariableDescription</span>
<span class="rem">'System::VariableID</span>
<span class="rem">'System::VariableName</span>
<span class="rem">'System::VariableValue</span>

<span class="kwrd">Public</span> <span class="kwrd">Sub</span> Main()
    <span class="kwrd">Dim</span> S <span class="kwrd">As</span> <span class="kwrd">String</span>

    <span class="rem">'Building a string that proof that the values of the variables</span>
    <span class="rem">' is originated from the event fires in the child package</span>
    S = <span class="str">"VariableName: "</span> &amp; Dts.Variables(<span class="str">"System::VariableName"</span>) _
      .Value.ToString() &amp; vbCrLf _
      &amp; <span class="str">"VariableID: "</span> &amp; Dts.Variables(<span class="str">"System::VariableID"</span>) _
      .Value.ToString() &amp; vbCrLf _
      &amp; <span class="str">"VariableDescription: "</span> &amp; Dts.Variables(<span class="str">"System::VariableDescription"</span>) _
      .Value.ToString() &amp; vbCrLf _
      &amp; <span class="str">"VariableValue: "</span> &amp; Dts.Variables(<span class="str">"System::VariableValue"</span>) _
      .Value.ToString() &amp; vbCrLf _
      &amp; <span class="str">"TaskName: "</span> &amp; Dts.Variables(<span class="str">"System::TaskName"</span>) _
      .Value.ToString() &amp; vbCrLf _
      &amp; <span class="str">"SourceName: "</span> &amp; Dts.Variables(<span class="str">"System::SourceName"</span>) _
      .Value.ToString()

    <span class="rem">'Showing the string value as a message box</span>
    MsgBox(S)

    Dts.TaskResult = ScriptResults.Success
<span class="kwrd">End</span> <span class="kwrd">Sub</span></pre>
<p><em>Note I’m not telling you here how to log the event, but just showing which variables are available for usage, and how to manipulate this variables from the event fire method</em></p>
<p>Here is a screen shot of the child package:</p>
<p><a href="http://sqlserverjedi.files.wordpress.com/2012/01/image2.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="The child package" src="http://sqlserverjedi.files.wordpress.com/2012/01/image_thumb2.png?w=602&#038;h=668" alt="The child package" width="602" height="668" border="0" /></a></p>
<p>The first script task is there just to proof the fact that the event is not fired, unless we set the event on a variable.</p>
<p>The second script task is where the magic is done, let’s look into the code:</p>
<pre class="csharpcode"><span class="kwrd">Public</span> <span class="kwrd">Sub</span> Main()

        Dts.Events().FireCustomEvent(<span class="str">"OnVariableValueChanged"</span>, _
                                     <span class="str">""</span>, _
                                     <span class="kwrd">New</span> <span class="kwrd">Object</span>(3) _
                                        { _
                                        <span class="str">"First Value"</span>, _
                                        <span class="str">"Second Value"</span>, _
                                        <span class="str">"Third Value"</span>, _
                                        <span class="str">"Forth Value"</span>}, _
                                     <span class="str">""</span>, _
                                     <span class="kwrd">False</span>)

        Dts.TaskResult = ScriptResults.Success
    <span class="kwrd">End</span> Sub</pre>
<p>&nbsp;</p>
<p>What we are doing here is this, we fire a custom event, of type OnVariableValueChanged. The FireCustomEvent can take an object, as the third parameter, and this object is later used by the SSIS Event Handler. I’ve doing some testing, and found out that at least 4 items can be included in this object, and that this 4 objects correspond to 4 SSIS system variables, which are accessible in the SSIS Event Handler. All 4 are strings, so we must use strings, to prevent errors.</p>
<p>To illustrate that, I’m sending 4 text values, let’s look into what happens when we ran the parent package:</p>
<p><a href="http://sqlserverjedi.files.wordpress.com/2012/01/image3.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="Running the parent package" src="http://sqlserverjedi.files.wordpress.com/2012/01/image_thumb3.png?w=602&#038;h=422" alt="Running the parent package" width="602" height="422" border="0" /></a></p>
<p>Let’s zoom in:</p>
<p><a href="http://sqlserverjedi.files.wordpress.com/2012/01/image4.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="The message box" src="http://sqlserverjedi.files.wordpress.com/2012/01/image_thumb4.png?w=602&#038;h=327" alt="The message box" width="602" height="327" border="0" /></a></p>
<p>In real life, we will use this 4 strings to send information about the custom event, it’s source, level, severity what ever is relevant for the specific system requirements.</p>
<p>&nbsp;</p>
<p>The entire project is available for <a href="https://skydrive.live.com/redir.aspx?cid=c0e257eba9013a35&amp;resid=C0E257EBA9013A35!108&amp;parid=C0E257EBA9013A35!107&amp;authkey=!AJUcGxZOteRA_Lo" target="_blank">download</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlserverjedi.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlserverjedi.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlserverjedi.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlserverjedi.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlserverjedi.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlserverjedi.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlserverjedi.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlserverjedi.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlserverjedi.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlserverjedi.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlserverjedi.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlserverjedi.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlserverjedi.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlserverjedi.wordpress.com/141/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlserverjedi.wordpress.com&amp;blog=28511675&amp;post=141&amp;subd=sqlserverjedi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlserverjedi.wordpress.com/2012/01/05/catch-custom-events-with-ssis-event-handler/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e5a38ef3957aede031fbf94c2c6ec260?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sirpadk</media:title>
		</media:content>

		<media:content url="http://sqlserverjedi.files.wordpress.com/2012/01/image_thumb.png" medium="image">
			<media:title type="html">The parent package</media:title>
		</media:content>

		<media:content url="http://sqlserverjedi.files.wordpress.com/2012/01/image_thumb1.png" medium="image">
			<media:title type="html">The Parent Package Event Handler</media:title>
		</media:content>

		<media:content url="http://sqlserverjedi.files.wordpress.com/2012/01/image_thumb2.png" medium="image">
			<media:title type="html">The child package</media:title>
		</media:content>

		<media:content url="http://sqlserverjedi.files.wordpress.com/2012/01/image_thumb3.png" medium="image">
			<media:title type="html">Running the parent package</media:title>
		</media:content>

		<media:content url="http://sqlserverjedi.files.wordpress.com/2012/01/image_thumb4.png" medium="image">
			<media:title type="html">The message box</media:title>
		</media:content>
	</item>
		<item>
		<title>New Localizations for Azure DateStream</title>
		<link>http://sqlserverjedi.wordpress.com/2011/12/08/new-localizations-for-azure-datestream/</link>
		<comments>http://sqlserverjedi.wordpress.com/2011/12/08/new-localizations-for-azure-datestream/#comments</comments>
		<pubDate>Thu, 08 Dec 2011 09:33:04 +0000</pubDate>
		<dc:creator>sirpadk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[DataMarket]]></category>
		<category><![CDATA[Date Dimension]]></category>
		<category><![CDATA[DateStream]]></category>

		<guid isPermaLink="false">http://sqlserverjedi.wordpress.com/2011/12/08/new-localizations-for-azure-datestream/</guid>
		<description><![CDATA[When I saw that Boyan Penev (blog) together with the SQL Azure Team had put a date dimension feed for free on the DataMarket, I thought wouldn&#8217;t it be great if we all contribute to the content of this valuable free data feeds? I come from Israel, and I live in Denmark. So I thought that I&#8217;ll be able [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlserverjedi.wordpress.com&amp;blog=28511675&amp;post=117&amp;subd=sqlserverjedi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When I saw that Boyan Penev (<a title="blog" href="http://www.bp-msbi.com/" target="_blank">blog</a>) together with the SQL Azure Team had put a date dimension feed for free on the DataMarket, I thought wouldn&#8217;t it be great if we all contribute to the content of this valuable free data feeds?</p>
<p>I come from Israel, and I live in Denmark. So I thought that I&#8217;ll be able to contribute with a translation of the calendar to danish and Hebrew. I contacted Boyan, and sent him the translated versions.</p>
<p>I was happy to read this morning that the translated feeds are now available, for free, on the <a title="DateStream" href="https://datamarket.azure.com/dataset/1542c52d-d466-4094-a801-9ef8fd7c6485" target="_blank">DataMarket</a>. 4 new languages were added (Hebrew, Danish, German and Bulgarian), and other languages are on the way.</p>
<p>I hope you&#8217;ll find this information useful.</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlserverjedi.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlserverjedi.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlserverjedi.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlserverjedi.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlserverjedi.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlserverjedi.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlserverjedi.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlserverjedi.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlserverjedi.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlserverjedi.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlserverjedi.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlserverjedi.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlserverjedi.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlserverjedi.wordpress.com/117/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlserverjedi.wordpress.com&amp;blog=28511675&amp;post=117&amp;subd=sqlserverjedi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlserverjedi.wordpress.com/2011/12/08/new-localizations-for-azure-datestream/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e5a38ef3957aede031fbf94c2c6ec260?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sirpadk</media:title>
		</media:content>
	</item>
		<item>
		<title>Using Filtered Index to Maintain Unique Key Combinations</title>
		<link>http://sqlserverjedi.wordpress.com/2011/11/17/using-filtered-index-to-maintain-unique-key-combinations/</link>
		<comments>http://sqlserverjedi.wordpress.com/2011/11/17/using-filtered-index-to-maintain-unique-key-combinations/#comments</comments>
		<pubDate>Thu, 17 Nov 2011 22:41:00 +0000</pubDate>
		<dc:creator>sirpadk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Data Integrity]]></category>
		<category><![CDATA[Datawarehouse]]></category>
		<category><![CDATA[Filtered Index]]></category>
		<category><![CDATA[Index]]></category>
		<category><![CDATA[Many to many]]></category>

		<guid isPermaLink="false">https://sqlserverjedi.wordpress.com/?p=33</guid>
		<description><![CDATA[When building a datawarehouse project, the usage of many to many tables is done to support multiple natural keys which are mapped to the same surrogate key. This is happening often with products and EAN codes. Each version of the same product will get a different EAN code, cause that make sense for the inventory [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlserverjedi.wordpress.com&amp;blog=28511675&amp;post=33&amp;subd=sqlserverjedi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When building a datawarehouse project, the usage of many to many tables is done to support multiple natural keys which are mapped to the same surrogate key. This is happening often with products and EAN codes. Each version of the same product will get a different EAN code, cause that make sense for the inventory guys who work in the warehouse, but  for analysis from the marketing department’s point of view, the product is the same, and sometimes we want to just add the sales of all versions of the same products to measure how many liters of “Orange Juice” were sold in a given month, regardless of the package variant (normal size bottle vs promotion 10% more bottle).</p>
<p>Another issue with EAN code is that EAN codes are suppose to be unique world wide, but it’s OK and common practice to reuse EAN codes which have been out of the market for 3 months. Because EAN codes cost money, companies reuse old EAN codes.</p>
<p>You can read about how to solve these issues using map tables at Thomas Kejser’s Database Blog<br />
(<a href="http://blog.kejser.org/2011/08/04/transforming-source-keys-to-real-keys-part-1-introducing-map-tables/" target="_blank">part 1</a> – <a href="http://blog.kejser.org/2011/08/15/transforming-source-keys-to-real-keys-part-2-using-maps-to-fix-key-problems/" target="_blank">part 2</a>)</p>
<p>What I want to show you is how you can maintain the uniqueness of your mapping table using filtered indexes.</p>
<p>So let’s describe the problem first:</p>
<p>We have a table <strong><em>Product</em></strong> and a table <strong><em>ProductEAN</em></strong>, which represents the many to many relations that may occur between a products and EAN codes. The <strong><em>ProductEAN</em></strong> table includes some columns which specify the date span ,for which the EAN mapping is relevant, this is done to support reload of historic data in the right context, this is also marked using a boolean columns <strong><em>IsActive</em></strong>. There is also a boolean indicator for which EAN is the default EAN, that is the EAN we wish to use in the a report.</p>
<p><a href="http://sqlserverjedi.files.wordpress.com/2011/11/product-to-productean.jpg"><img style="background-image:none;padding-left:0;padding-right:0;display:block;float:none;margin-left:auto;margin-right:auto;padding-top:0;border-width:0;" title="Product to ProductEAN" src="http://sqlserverjedi.files.wordpress.com/2011/11/product-to-productean_thumb.jpg?w=508&#038;h=256" alt="Product to ProductEAN" width="508" height="256" border="0" /></a></p>
<p>Now the thing is that we wish to make sure that invalid data is not entered to the <strong><em>ProductEAN</em></strong> table. Invalid data can be if the same <strong><em>EAN</em></strong> is mapped to 2 different <strong><em>ProductKey</em></strong>, and both of them are an active mapping. Another case of invalid data is if more than one <strong><em>EAN</em></strong> is marked to be the default for the same <strong><em>ProductKey</em></strong>.</p>
<p>We can implement this data consistency checks using filtered indexes. Now it’s not why Microsoft chose to implement them, never the less it gets the job done!</p>
<pre class="csharpcode"><span class="kwrd">create</span> <span class="kwrd">unique</span> <span class="kwrd">index</span> UIX_ProductEAN_Only_One_Active_Product_Per_EAN
<span class="kwrd">on</span> ProductEAN (EAN) <span class="kwrd">where</span> IsActive = 1;

<span class="kwrd">create</span> <span class="kwrd">unique</span> <span class="kwrd">index</span> UIX_ProductEAN_Only_One_Default_EAN_Per_Product
<span class="kwrd">on</span> ProductEAN (Productkey) <span class="kwrd">where</span> IsDefault = 1;</pre>
<p align="left">So what is it we are doing here?</p>
<p align="left">A unique index will not allow duplicates to occur. So when we build an unique index on the <strong><em>EAN</em></strong> column, we force that the same <strong><em>EAN</em></strong> code will not be entered twice to the table. Note that this alone is not enough in order to solve the problem, because we do allow the same EAN to exist multiple times, but we allow only <span style="text-decoration:underline;">one active relation for each EAN</span>, so by adding the<strong> where</strong> clause to the index definition, we are telling the database engine to build the unique index <strong>only</strong> on the columns which have the <strong><em>IsActive value = 1</em></strong>, hence we are forcing uniqueness only on a sub set of the table, which apply to the condition in the where clause .</p>
<p align="left">Lets look into some data:</p>
<pre class="csharpcode"><span class="kwrd">select</span> *
<span class="kwrd">from</span> ProductEAN
<span class="kwrd">where</span> EAN = <span class="str">'5019487040114'</span></pre>
<p><a href="http://sqlserverjedi.files.wordpress.com/2011/11/image.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://sqlserverjedi.files.wordpress.com/2011/11/image_thumb.png?w=594&#038;h=90" alt="image" width="594" height="90" border="0" /></a></p>
<p align="left">Any attempt to invalidate the business rule will result in a invalidation of the index, and the query will fail.</p>
<pre class="csharpcode"><span class="kwrd">update</span> ProductEAN <span class="kwrd">set</span> IsActive = 1 <span class="kwrd">where</span> ProductEANKey = <span class="str">8</span></pre>
<p>This will result in the following error message:</p>
<p><span style="color:#ff0000;">Msg 2601, Level 14, State 1, Line 1</span></p>
<p><span style="color:#ff0000;">Cannot insert duplicate key row in object &#8216;dbo.ProductEAN&#8217; with unique index <strong>&#8216;UIX_ProductEAN_Only_One_Active_Product_Per_EAN&#8217;</strong>.</span></p>
<p><span style="color:#ff0000;">The duplicate key value is (5019487040114).</span></p>
<p><span style="color:#ff0000;">The statement has been terminated.</span></p>
<p>To summarize, we are able to enforce uniqueness on a sub set of a table, using a unique filtered index. This allows us to maintain the business rule of single active relation, and/or single default relation for each member in the many to many relation.</p>
<p>Remember to name the indexes wisely, so that the error message becomes self describing.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlserverjedi.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlserverjedi.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlserverjedi.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlserverjedi.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlserverjedi.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlserverjedi.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlserverjedi.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlserverjedi.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlserverjedi.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlserverjedi.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlserverjedi.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlserverjedi.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlserverjedi.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlserverjedi.wordpress.com/33/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlserverjedi.wordpress.com&amp;blog=28511675&amp;post=33&amp;subd=sqlserverjedi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlserverjedi.wordpress.com/2011/11/17/using-filtered-index-to-maintain-unique-key-combinations/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e5a38ef3957aede031fbf94c2c6ec260?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sirpadk</media:title>
		</media:content>

		<media:content url="http://sqlserverjedi.files.wordpress.com/2011/11/product-to-productean_thumb.jpg" medium="image">
			<media:title type="html">Product to ProductEAN</media:title>
		</media:content>

		<media:content url="http://sqlserverjedi.files.wordpress.com/2011/11/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
	</channel>
</rss>
