<?xml version="1.0" encoding="iso-8859-1"?><!-- generator="b2evolution/4.0.3" -->
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Data Management - Author(s): Christiaan Baes (chrissie1)</title>
		<link>http://blogs.lessthandot.com/index.php/DataMgmt/</link>
		<atom:link rel="self" type="application/rss+xml" href="http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2" />
		<description></description>
		<language>en-GB</language>
		<docs>http://blogs.law.harvard.edu/tech/rss</docs>
		<admin:generatorAgent rdf:resource="http://b2evolution.net/?v=4.0.3"/>
		<ttl>60</ttl>
				<item>
			<title>Another solution for my caching problem with servicestack.text, dapper and sql server.</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/another-solution-for-my-caching</link>
			<pubDate>Sat, 09 Mar 2013 16:23:00 +0000</pubDate>			<dc:creator>Christiaan Baes (chrissie1)</dc:creator>
			<category domain="main">Database Programming</category>			<guid isPermaLink="false">2138@http://blogs.lessthandot.com/</guid>
						<description>&lt;h2&gt;Introduction&lt;/h2&gt;

&lt;p&gt;My problem is the speed of the datastore I am querying. I won&#039;t name the vendor but their API is horrible. If I want to get all 3000 objects of a certain type I need to first get all the Id&#039;s from the latest versions of those objects, then I have to get the properties of each of those objects, if I am unlucky those objects have subobjects and then I have to query those too. So to get 3000 objects with 2 subobjects I need to do 9001 queries. Needless to say this will be slow. &lt;/p&gt;

&lt;p&gt;Last week I had &lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/redis-and-vb-net&quot;&gt;a look at redis&lt;/a&gt; to easily cache these objects on my webserver.&lt;/p&gt;

&lt;p&gt;Redis is a good solution but it is only production ready on Linux, and our ops-team was not really happy with it. Even though I got permission to set up the linux server on our ESX-servers, I was still looking at other solutions.&lt;/p&gt;

&lt;p&gt;Today I might have found such a solution. I can use SQL-server and serialize the objects as json.&lt;/p&gt;

&lt;h2&gt;The database&lt;/h2&gt;

&lt;p&gt;Not really a database since it is just one table.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb11178&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;CREATE&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;TABLE&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;dbo&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt;.&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #00AF00;&quot;&gt;objects&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;Id&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;INT&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;IDENTITY&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #000;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; NOT NULL,&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;version&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt; &amp;nbsp;&lt;span style=&quot;color: #0000FF;&quot;&gt;INT&lt;/span&gt; NOT NULL,&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;objid&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #0000FF;&quot;&gt;INT&lt;/span&gt; NOT NULL,&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;language&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;INT&lt;/span&gt; NOT NULL,&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt; &amp;nbsp;&lt;span style=&quot;color: #0000FF;&quot;&gt;NVARCHAR&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF00FF;&quot;&gt;MAX&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; NOT NULL,&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;objtype&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;INT&lt;/span&gt; NOT NULL, &lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;PRIMARY&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;KEY&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;CLUSTERED&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;Id&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;ASC&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb77298&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Not sure how this will scale but I am pretty sure that we will not get more than 1 million rows in there any time soon. At the moment it is less than 100k rows.&lt;/p&gt;

&lt;p&gt;I can now use &lt;a href=&quot;https://code.google.com/p/dapper-dot-net/&quot;&gt;dapper &lt;/a&gt;and &lt;a href=&quot;https://github.com/ServiceStack/ServiceStack.Text&quot;&gt;servicestack.text&lt;/a&gt; to get the data in and out of there.&lt;/p&gt;

&lt;h2&gt;The code&lt;/h2&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;text&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;text&quot; id=&quot;cb12204&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;Imports Dapper&lt;br /&gt;Imports System.Data.SqlClient&lt;br /&gt;Imports ServiceStack.Text&lt;br /&gt;&amp;nbsp;&lt;br /&gt;Module Module1&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; Sub Main()&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Dim con As New SqlConnection(&amp;quot;Server=christiaan-pc;Database=cache;Trusted_Connection=True;&amp;quot;)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; con.Open()&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; con.Execute(&amp;quot;delete from objects&amp;quot;)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Dim object1s = New List(Of object1)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Dim object2s = New List(Of object2)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Dim s As New Stopwatch&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.WriteLine(&amp;quot;Adding to database&amp;quot;)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; s.Start()&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; For i = 0 To 10000&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; object1s.Add(New object1() With {.id = i, .name = &amp;quot;object1_&amp;quot; &amp;amp; i, .version = 1})&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; object2s.Add(New object2() With {.id = i, .name = &amp;quot;object2_&amp;quot; &amp;amp; i, .version = 1})&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Next&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Dim objects = New List(Of databaseobject)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; For Each object1 In object1s&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; objects.Add(New databaseobject() With {.language = 102, .objid = object1.id, .version = object1.version, .value = object1.SerializeToString(), .objtype = 1})&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Next&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; For Each object2 In object2s&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; objects.Add(New databaseobject() With {.language = 102, .objid = object2.id, .version = object2.version, .value = object2.SerializeToString(), .objtype = 2})&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Next&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; con.Execute(&amp;quot;insert objects(objid, version, language, value, objtype) values (@objid, @version,@language,@value,@objtype)&amp;quot;,&lt;br /&gt;&amp;nbsp; &amp;nbsp; objects)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; s.Stop()&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.WriteLine(s.ElapsedMilliseconds)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.WriteLine(&amp;quot;Fetching from database&amp;quot;)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; s.Restart()&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Dim l = con.Query(Of databaseobject)(&amp;quot;select objid, version, language, value, objtype from objects where objtype = 1&amp;quot;)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Dim obj1 As object1&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; For Each m In l&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; obj1 = m.value.FromJson(Of object1)()&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Next&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; l = con.Query(Of databaseobject)(&amp;quot;select objid, version, language, value, objtype from objects where objtype = 2&amp;quot;)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Dim obj2As object2&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; For Each m In l&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; obj2 &amp;nbsp;= m.value.FromJson(Of object2)()&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Next&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; s.Stop()&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.WriteLine(s.ElapsedMilliseconds)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.ReadLine()&lt;br /&gt;&amp;nbsp; &amp;nbsp; End Sub&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; Public Class databaseobject&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Public Property id As Integer&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Public Property objid As Integer&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Public Property version As Integer&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Public Property language As Integer&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Public Property objtype As Integer&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Public Property value As String&lt;br /&gt;&amp;nbsp; &amp;nbsp; End Class&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; Public Class object1&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Public Property name As String&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Public Property id As Integer&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Public Property version As Integer&lt;br /&gt;&amp;nbsp; &amp;nbsp; End Class&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; Public Class object2&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Public Property name As String&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Public Property id As Integer&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Public Property version As Integer&lt;br /&gt;&amp;nbsp; &amp;nbsp; End Class&lt;br /&gt;End Module&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb51840&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So I am adding 2 times 10k objects to the database and after that I rehydrate them again.&lt;/p&gt;

&lt;p&gt;On my computer this is the result.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;Adding to database&lt;br /&gt;
13317&lt;br /&gt;
Fetching from database&lt;br /&gt;
199&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;That&#039;s more then reasonable. Considering it takes 28 seconds to get 3000 objects from the datastore.&lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;All though I think redis would be a good solution, I don&#039;t think it is an ideal solution for our situation.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/another-solution-for-my-caching&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<h2>Introduction</h2>

<p>My problem is the speed of the datastore I am querying. I won't name the vendor but their API is horrible. If I want to get all 3000 objects of a certain type I need to first get all the Id's from the latest versions of those objects, then I have to get the properties of each of those objects, if I am unlucky those objects have subobjects and then I have to query those too. So to get 3000 objects with 2 subobjects I need to do 9001 queries. Needless to say this will be slow. </p>

<p>Last week I had <a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/redis-and-vb-net">a look at redis</a> to easily cache these objects on my webserver.</p>

<p>Redis is a good solution but it is only production ready on Linux, and our ops-team was not really happy with it. Even though I got permission to set up the linux server on our ESX-servers, I was still looking at other solutions.</p>

<p>Today I might have found such a solution. I can use SQL-server and serialize the objects as json.</p>

<h2>The database</h2>

<p>Not really a database since it is just one table.</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb7942'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb7942','cb29038'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb7942" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> <span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span><span style="color: #00AF00;">objects</span><span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#40;</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #808080;">&#91;</span>Id<span style="color: #808080;">&#93;</span> &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INT</span> <span style="color: #0000FF;">IDENTITY</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">1</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> NOT NULL,</li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #808080;">&#91;</span>version<span style="color: #808080;">&#93;</span> &nbsp;<span style="color: #0000FF;">INT</span> NOT NULL,</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #808080;">&#91;</span>objid<span style="color: #808080;">&#93;</span> &nbsp; &nbsp;<span style="color: #0000FF;">INT</span> NOT NULL,</li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">language</span><span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">INT</span> NOT NULL,</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">value</span><span style="color: #808080;">&#93;</span> &nbsp;<span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">MAX</span><span style="color: #808080;">&#41;</span> NOT NULL,</li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #808080;">&#91;</span>objtype<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">INT</span> NOT NULL, </li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0000FF;">PRIMARY</span> <span style="color: #0000FF;">KEY</span> <span style="color: #0000FF;">CLUSTERED</span> <span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>Id<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">ASC</span><span style="color: #808080;">&#41;</span></li><li style="" class="li1"><span style="color: #808080;">&#41;</span>;</li></ol></div><div id="cb29038" style="display: none; color: red;"></div></div></div>

<p>Not sure how this will scale but I am pretty sure that we will not get more than 1 million rows in there any time soon. At the moment it is less than 100k rows.</p>

<p>I can now use <a href="https://code.google.com/p/dapper-dot-net/">dapper </a>and <a href="https://github.com/ServiceStack/ServiceStack.Text">servicestack.text</a> to get the data in and out of there.</p>

<h2>The code</h2>

<div class="codebox"><div class="codeheader"><span>text</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb89903'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb89903','cb71022'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="text" id="cb89903" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">Imports Dapper</li><li style="" class="li2">Imports System.Data.SqlClient</li><li style="" class="li1">Imports ServiceStack.Text</li><li style="" class="li2">&nbsp;</li><li style="" class="li1">Module Module1</li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; Sub Main()</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; Dim con As New SqlConnection(&quot;Server=christiaan-pc;Database=cache;Trusted_Connection=True;&quot;)</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; con.Open()</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; con.Execute(&quot;delete from objects&quot;)</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; Dim object1s = New List(Of object1)</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; Dim object2s = New List(Of object2)</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; Dim s As New Stopwatch</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Adding to database&quot;)</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; s.Start()</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; For i = 0 To 10000</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; object1s.Add(New object1() With {.id = i, .name = &quot;object1_&quot; &amp; i, .version = 1})</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; object2s.Add(New object2() With {.id = i, .name = &quot;object2_&quot; &amp; i, .version = 1})</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; Next</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; Dim objects = New List(Of databaseobject)</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; For Each object1 In object1s</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; objects.Add(New databaseobject() With {.language = 102, .objid = object1.id, .version = object1.version, .value = object1.SerializeToString(), .objtype = 1})</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; Next</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; For Each object2 In object2s</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; objects.Add(New databaseobject() With {.language = 102, .objid = object2.id, .version = object2.version, .value = object2.SerializeToString(), .objtype = 2})</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; Next</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; con.Execute(&quot;insert objects(objid, version, language, value, objtype) values (@objid, @version,@language,@value,@objtype)&quot;,</li><li style="" class="li2">&nbsp; &nbsp; objects)</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; s.Stop()</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine(s.ElapsedMilliseconds)</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Fetching from database&quot;)</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; s.Restart()</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; Dim l = con.Query(Of databaseobject)(&quot;select objid, version, language, value, objtype from objects where objtype = 1&quot;)</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; Dim obj1 As object1</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; For Each m In l</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj1 = m.value.FromJson(Of object1)()</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; Next</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; l = con.Query(Of databaseobject)(&quot;select objid, version, language, value, objtype from objects where objtype = 2&quot;)</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; Dim obj2As object2</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; For Each m In l</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj2 &nbsp;= m.value.FromJson(Of object2)()</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; Next</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; s.Stop()</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine(s.ElapsedMilliseconds)</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; Console.ReadLine()</li><li style="" class="li2">&nbsp; &nbsp; End Sub</li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; Public Class databaseobject</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; Public Property id As Integer</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; Public Property objid As Integer</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; Public Property version As Integer</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; Public Property language As Integer</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; Public Property objtype As Integer</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; Public Property value As String</li><li style="" class="li1">&nbsp; &nbsp; End Class</li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; Public Class object1</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; Public Property name As String</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; Public Property id As Integer</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; Public Property version As Integer</li><li style="" class="li1">&nbsp; &nbsp; End Class</li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; Public Class object2</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; Public Property name As String</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; Public Property id As Integer</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; Public Property version As Integer</li><li style="" class="li1">&nbsp; &nbsp; End Class</li><li style="" class="li2">End Module</li></ol></div><div id="cb71022" style="display: none; color: red;"></div></div></div>

<p>So I am adding 2 times 10k objects to the database and after that I rehydrate them again.</p>

<p>On my computer this is the result.</p>

<blockquote><p>Adding to database<br />
13317<br />
Fetching from database<br />
199</p></blockquote>

<p>That's more then reasonable. Considering it takes 28 seconds to get 3000 objects from the datastore.</p>

<h2>Conclusion</h2>

<p>All though I think redis would be a good solution, I don't think it is an ideal solution for our situation.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/another-solution-for-my-caching">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/another-solution-for-my-caching#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=2138</wfw:commentRss>
		</item>
				<item>
			<title>Redis and VB.Net</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/redis-and-vb-net</link>
			<pubDate>Sun, 03 Mar 2013 17:36:00 +0000</pubDate>			<dc:creator>Christiaan Baes (chrissie1)</dc:creator>
			<category domain="main">Database Programming</category>			<guid isPermaLink="false">2130@http://blogs.lessthandot.com/</guid>
						<description>&lt;h2&gt;Introduction&lt;/h2&gt;

&lt;p&gt;So I thought I needed redis to do some much needed caching for an app I am writting. And I was right, as I often am. &lt;/p&gt;

&lt;p&gt;So I installed &lt;a href=&quot;http://redis.io&quot;&gt;redis&lt;/a&gt; and used the &lt;a href=&quot;https://github.com/ServiceStack/ServiceStack.Redis&quot;&gt;.net redis client&lt;/a&gt; from the always brilliant Demis Bellot.&lt;/p&gt;

&lt;p&gt;Redis is a key-value database, a dictionary on steroids. It is great for caching. And it is fast at what it does by keeping most things in memory.&lt;/p&gt;

&lt;h2&gt;Redis&lt;/h2&gt;

&lt;p&gt;First I used the windows version of redis and that even worked, but it is not production ready. So I decided to install a linux VM with redis on it.&lt;/p&gt;

&lt;p&gt;I downloaded mint 14 and did apt-get install redis-server. Then you need to change the file in /etc/res/redis.conf and comment the line bind 127.0.0.1 or change it to bind 0.0.0.0. &lt;/p&gt;

&lt;p&gt;I used VMWare workstation 8 and I had to use NAT translation for the network and add forward the 6379 port.&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/users/chrissie1/redis/redis1.png?mtime=1362333768&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/users/chrissie1/redis/redis1.png?mtime=1362333768&quot; width=&quot;602&quot; height=&quot;612&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;you can check if your redis server works by doing &lt;code class=&quot;codespan&quot;&gt;redis-cli ping&lt;/code&gt; on the server. This should return PONG. To be sure the binding works you should try &lt;code class=&quot;codespan&quot;&gt;redis-cli -h ipaddress ping&lt;/code&gt;. where you change ipaddress with the ip-address of the linux machine. This should also give PONG. &lt;/p&gt;

&lt;p&gt;You can now do the same on the host to check if you can connect. &lt;/p&gt;

&lt;p&gt;If all works well you can start writing to your redis server. And we might do some reading to.&lt;/p&gt;

&lt;h2&gt;Redis-client&lt;/h2&gt;

&lt;p&gt;Here is our model.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;vbnet&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;vbnet&quot; id=&quot;cb65232&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;Public&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Class&lt;/span&gt; Mandate&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Public&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Property&lt;/span&gt; Id &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;String&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Public&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Property&lt;/span&gt; Version &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Integer&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Public&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Property&lt;/span&gt; Name &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;String&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Class&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb24836&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Firstly you need to nuget servicestack.redis.&lt;/p&gt;

&lt;p&gt;The following code writes some entries to our redis server.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;vbnet&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;vbnet&quot; id=&quot;cb42861&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;Using redisClient = &lt;span style=&quot;color: #0600FF;&quot;&gt;New&lt;/span&gt; RedisClient&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;ipaddressofthelinuxvm&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Dim&lt;/span&gt; client = redisClient.&lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;Of Mandate&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; client.&lt;span style=&quot;color: #000000;&quot;&gt;GetAllKeys&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;Count&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;PrintDump&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;For&lt;/span&gt; i &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Integer&lt;/span&gt; = &lt;span style=&quot;color: #FF0000;&quot;&gt;1&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;To&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;500&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; client.&lt;span style=&quot;color: #000000;&quot;&gt;SetEntry&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;i, &lt;span style=&quot;color: #0600FF;&quot;&gt;New&lt;/span&gt; Mandate&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; With &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;Id&lt;/span&gt; = i, .&lt;span style=&quot;color: #000000;&quot;&gt;Version&lt;/span&gt; = &lt;span style=&quot;color: #FF0000;&quot;&gt;1&lt;/span&gt;, .&lt;span style=&quot;color: #000000;&quot;&gt;Name&lt;/span&gt; = &lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;Name&amp;quot;&lt;/span&gt; &amp;amp; i&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Next&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Dim&lt;/span&gt; mandate5 = client.&lt;span style=&quot;color: #000000;&quot;&gt;GetValue&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mandate5.&lt;span style=&quot;color: #000000;&quot;&gt;Version&lt;/span&gt; += &lt;span style=&quot;color: #FF0000;&quot;&gt;1&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; client.&lt;span style=&quot;color: #000000;&quot;&gt;SetEntry&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;5&lt;/span&gt;, mandate5&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; client.&lt;span style=&quot;color: #000000;&quot;&gt;GetValue&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;PrintDump&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; client.&lt;span style=&quot;color: #000000;&quot;&gt;GetAllKeys&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;Where&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;Function&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; Not x.&lt;span style=&quot;color: #000000;&quot;&gt;Contains&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;ids&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;Count&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;PrintDump&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; client.&lt;span style=&quot;color: #000000;&quot;&gt;Save&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; Using&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.&lt;span style=&quot;color: #000000;&quot;&gt;ReadLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb92310&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If you run the above you will get.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;0&lt;br /&gt;
{&lt;br /&gt;
        Id: 5,&lt;br /&gt;
        Version: 2,&lt;br /&gt;
        Name: Name5&lt;br /&gt;
}&lt;br /&gt;
500&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;On a second run you will get.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;501&lt;br /&gt;
{&lt;br /&gt;
        Id: 5,&lt;br /&gt;
        Version: 2,&lt;br /&gt;
        Name: Name5&lt;br /&gt;
}&lt;br /&gt;
500&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So I add 500 objects but it tells me I have 501. The 501st is the id of the mandate class.&lt;/p&gt;

&lt;p&gt;I don&#039;t really need to do the save, since redis will do an autosave every so often (depends on your redis.conf).&lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;It is here that I pretend that redis is easy to use and to set up. And it is, just not for me ;-).&lt;/p&gt;

&lt;p&gt;I would like to thank Demis for setting me on the way to solving my connectivity problems with the VM. &lt;/p&gt;



&lt;p&gt;The second time it won&#039;t add another 500 entries, it will update the ones that are there.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/redis-and-vb-net&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<h2>Introduction</h2>

<p>So I thought I needed redis to do some much needed caching for an app I am writting. And I was right, as I often am. </p>

<p>So I installed <a href="http://redis.io">redis</a> and used the <a href="https://github.com/ServiceStack/ServiceStack.Redis">.net redis client</a> from the always brilliant Demis Bellot.</p>

<p>Redis is a key-value database, a dictionary on steroids. It is great for caching. And it is fast at what it does by keeping most things in memory.</p>

<h2>Redis</h2>

<p>First I used the windows version of redis and that even worked, but it is not production ready. So I decided to install a linux VM with redis on it.</p>

<p>I downloaded mint 14 and did apt-get install redis-server. Then you need to change the file in /etc/res/redis.conf and comment the line bind 127.0.0.1 or change it to bind 0.0.0.0. </p>

<p>I used VMWare workstation 8 and I had to use NAT translation for the network and add forward the 6379 port.</p>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/users/chrissie1/redis/redis1.png?mtime=1362333768"><img alt="" src="http://blogs.lessthandot.com/media/users/chrissie1/redis/redis1.png?mtime=1362333768" width="602" height="612" /></a></div>

<p>you can check if your redis server works by doing <code class="codespan">redis-cli ping</code> on the server. This should return PONG. To be sure the binding works you should try <code class="codespan">redis-cli -h ipaddress ping</code>. where you change ipaddress with the ip-address of the linux machine. This should also give PONG. </p>

<p>You can now do the same on the host to check if you can connect. </p>

<p>If all works well you can start writing to your redis server. And we might do some reading to.</p>

<h2>Redis-client</h2>

<p>Here is our model.</p>

<div class="codebox"><div class="codeheader"><span>vbnet</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb58432'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb58432','cb76346'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="vbnet" id="cb58432" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0600FF;">Public</span> <span style="color: #0600FF;">Class</span> Mandate</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Public</span> <span style="color: #0600FF;">Property</span> Id <span style="color: #0600FF;">As</span> <span style="color: #0600FF;">String</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Public</span> <span style="color: #0600FF;">Property</span> Version <span style="color: #0600FF;">As</span> <span style="color: #0600FF;">Integer</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Public</span> <span style="color: #0600FF;">Property</span> Name <span style="color: #0600FF;">As</span> <span style="color: #0600FF;">String</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Class</span></li></ol></div><div id="cb76346" style="display: none; color: red;"></div></div></div>

<p>Firstly you need to nuget servicestack.redis.</p>

<p>The following code writes some entries to our redis server.</p>

<div class="codebox"><div class="codeheader"><span>vbnet</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb90758'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb90758','cb60598'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="vbnet" id="cb90758" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">Using redisClient = <span style="color: #0600FF;">New</span> RedisClient<span style="color: #000000;">&#40;</span>ipaddressofthelinuxvm<span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> client = redisClient.<span style="color: #0600FF;">As</span><span style="color: #000000;">&#40;</span>Of Mandate<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; client.<span style="color: #000000;">GetAllKeys</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">Count</span>.<span style="color: #000000;">PrintDump</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">For</span> i <span style="color: #0600FF;">As</span> <span style="color: #0600FF;">Integer</span> = <span style="color: #FF0000;">1</span> <span style="color: #0600FF;">To</span> <span style="color: #FF0000;">500</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; client.<span style="color: #000000;">SetEntry</span><span style="color: #000000;">&#40;</span>i, <span style="color: #0600FF;">New</span> Mandate<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> With <span style="color: #000000;">&#123;</span>.<span style="color: #000000;">Id</span> = i, .<span style="color: #000000;">Version</span> = <span style="color: #FF0000;">1</span>, .<span style="color: #000000;">Name</span> = <span style="color: #0600FF;">&quot;Name&quot;</span> &amp; i<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Next</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> mandate5 = client.<span style="color: #000000;">GetValue</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">5</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mandate5.<span style="color: #000000;">Version</span> += <span style="color: #FF0000;">1</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; client.<span style="color: #000000;">SetEntry</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">5</span>, mandate5<span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; client.<span style="color: #000000;">GetValue</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">5</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">PrintDump</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; client.<span style="color: #000000;">GetAllKeys</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">Where</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">Function</span><span style="color: #000000;">&#40;</span>x<span style="color: #000000;">&#41;</span> Not x.<span style="color: #000000;">Contains</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">&quot;ids&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">Count</span>.<span style="color: #000000;">PrintDump</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; client.<span style="color: #000000;">Save</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> Using</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #000000;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li></ol></div><div id="cb60598" style="display: none; color: red;"></div></div></div>

<p>If you run the above you will get.</p>

<blockquote><p>0<br />
{<br />
        Id: 5,<br />
        Version: 2,<br />
        Name: Name5<br />
}<br />
500</p>
</blockquote>

<p>On a second run you will get.</p>

<blockquote><p>501<br />
{<br />
        Id: 5,<br />
        Version: 2,<br />
        Name: Name5<br />
}<br />
500</p>
</blockquote>

<p>So I add 500 objects but it tells me I have 501. The 501st is the id of the mandate class.</p>

<p>I don't really need to do the save, since redis will do an autosave every so often (depends on your redis.conf).</p>

<h2>Conclusion</h2>

<p>It is here that I pretend that redis is easy to use and to set up. And it is, just not for me ;-).</p>

<p>I would like to thank Demis for setting me on the way to solving my connectivity problems with the VM. </p>



<p>The second time it won't add another 500 entries, it will update the ones that are there.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/redis-and-vb-net">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/redis-and-vb-net#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=2130</wfw:commentRss>
		</item>
				<item>
			<title>Full outer join requires some thinking before use</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/MSSQLServer/full-outer-join-requires-some</link>
			<pubDate>Wed, 10 Oct 2012 06:03:00 +0000</pubDate>			<dc:creator>Christiaan Baes (chrissie1)</dc:creator>
			<category domain="main">Microsoft SQL Server</category>			<guid isPermaLink="false">1856@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;I don&#039;t need Full outer joins all that often. So when I do I have to think on what it will return me. &lt;/p&gt;

&lt;p&gt;You can go to &lt;a href=&quot;http://en.wikipedia.org/wiki/Join_(SQL)#Full_outer_join&quot;&gt;wikipedia&lt;/a&gt; to find the full explanation on full outer joins if you want to.&lt;/p&gt;

&lt;p&gt;But in short it is this.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;Conceptually, a full outer join combines the effect of applying both left and right outer joins. Where records in the FULL OUTER JOINed tables do not match, the result set will have NULL values for every column of the table that lacks a matching row. For those records that do match, a single row will be produced in the result set (containing fields populated from both tables).&lt;br /&gt;
For example, this allows us to see each employee who is in a department and each department that has an employee, but also see each employee who is not part of a department and each department which doesn&#039;t have an employee.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;What I needed was to combine the result of two queries where I did a sum by year and join on the year. &lt;/p&gt;

&lt;p&gt;Here is the testdate.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb59360&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;CREATE&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;TABLE&lt;/span&gt; #temp &lt;br /&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; Id &lt;span style=&quot;color: #0000FF;&quot;&gt;INT&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;IDENTITY&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #000;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;PRIMARY&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;KEY&lt;/span&gt; NOT NULL&lt;br /&gt;&amp;nbsp; &amp;nbsp; , DateIn &lt;span style=&quot;color: #0000FF;&quot;&gt;DATETIME&lt;/span&gt; NULL&lt;br /&gt;&amp;nbsp; &amp;nbsp; , DateOut &lt;span style=&quot;color: #0000FF;&quot;&gt;DATETIME&lt;/span&gt; NULL&lt;br /&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;GO&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;INTO&lt;/span&gt; #temp &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;DateIn, DateOut&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;VALUES&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;2012-10-10 9:38:45.757&#039;&lt;/span&gt;,null&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;INTO&lt;/span&gt; #temp &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;DateIn, DateOut&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;VALUES&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;2011-10-10 9:38:45.757&#039;&lt;/span&gt;,&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;2012-10-10 9:38:45.757&#039;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;INTO&lt;/span&gt; #temp &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;DateIn, DateOut&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;VALUES&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;2010-10-10 9:38:45.757&#039;&lt;/span&gt;,&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;2011-10-10 9:38:45.757&#039;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;INTO&lt;/span&gt; #temp &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;DateIn, DateOut&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;VALUES&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;2010-10-10 9:38:45.757&#039;&lt;/span&gt;,&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;2011-10-10 9:38:45.757&#039;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;INTO&lt;/span&gt; #temp &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;DateIn, DateOut&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;VALUES&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;2012-10-10 9:38:45.757&#039;&lt;/span&gt;,null&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;INTO&lt;/span&gt; #temp &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;DateIn, DateOut&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;VALUES&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;2011-10-10 9:38:45.757&#039;&lt;/span&gt;,&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;2012-10-10 9:38:45.757&#039;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;INTO&lt;/span&gt; #temp &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;DateIn, DateOut&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;VALUES&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;2009-10-10 9:38:45.757&#039;&lt;/span&gt;,&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;2010-10-10 9:38:45.757&#039;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;INTO&lt;/span&gt; #temp &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;DateIn, DateOut&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;VALUES&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;2009-10-10 9:38:45.757&#039;&lt;/span&gt;,&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;2010-10-10 9:38:45.757&#039;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;GO&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; Id, datein, dateout &lt;span style=&quot;color: #0000FF;&quot;&gt;FROM&lt;/span&gt; #temp&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;GO&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;DROP&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;TABLE&lt;/span&gt; #temp&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb49408&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And the desired result was something like this.&lt;/p&gt;

&lt;div class=&quot;tables&quot;&gt;
&lt;table&gt;
&lt;tr&gt;&lt;th&gt;Year&lt;/th&gt;&lt;th&gt;NumberIn&lt;/th&gt;&lt;th&gt;NumberOut&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;2009&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;2010&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;2011&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;2012&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;

&lt;p&gt;My first query was this.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb22431&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; DateInData.&lt;span style=&quot;color: #FF00FF;&quot;&gt;YEAR&lt;/span&gt;, &lt;span style=&quot;color: #FF00FF;&quot;&gt;COALESCE&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;numberin,&lt;span style=&quot;color: #000;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; numberin, &lt;span style=&quot;color: #FF00FF;&quot;&gt;COALESCE&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;numberout,&lt;span style=&quot;color: #000;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; numberout&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;FROM&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color: #FF00FF;&quot;&gt;YEAR&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;datein&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: #FF00FF;&quot;&gt;YEAR&lt;/span&gt;, &lt;span style=&quot;color: #FF00FF;&quot;&gt;COUNT&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;*&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; numberin &lt;span style=&quot;color: #0000FF;&quot;&gt;FROM&lt;/span&gt; #temp &lt;span style=&quot;color: #0000FF;&quot;&gt;GROUP&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;BY&lt;/span&gt; &lt;span style=&quot;color: #FF00FF;&quot;&gt;YEAR&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;datein&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;HAVING&lt;/span&gt; &lt;span style=&quot;color: #FF00FF;&quot;&gt;YEAR&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;datein&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;IS&lt;/span&gt; NOT NULL&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; DateInData&lt;br /&gt;&amp;nbsp; &amp;nbsp; FULL OUTER JOIN &lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color: #FF00FF;&quot;&gt;YEAR&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;dateout&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: #FF00FF;&quot;&gt;YEAR&lt;/span&gt;, &lt;span style=&quot;color: #FF00FF;&quot;&gt;COUNT&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;*&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; numberout &lt;span style=&quot;color: #0000FF;&quot;&gt;FROM&lt;/span&gt; #temp &lt;span style=&quot;color: #0000FF;&quot;&gt;GROUP&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;BY&lt;/span&gt; &lt;span style=&quot;color: #FF00FF;&quot;&gt;YEAR&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;dateout&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;HAVING&lt;/span&gt; &lt;span style=&quot;color: #FF00FF;&quot;&gt;YEAR&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;dateout&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;IS&lt;/span&gt; NOT NULL&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; DateOutData&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;ON&lt;/span&gt; DateInData.&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #FF00FF;&quot;&gt;YEAR&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt; = DateOutData.&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #FF00FF;&quot;&gt;YEAR&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb44738&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And hooray, that gives the correct results. So lets move on.&lt;/p&gt;

&lt;p&gt;Hold on. In the above I am assuming that datein will always be filled in. But my table definition says it is not a mandatory field.&lt;/p&gt;

&lt;p&gt;So what would happen if I had the following data in my table.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb66220&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;INTO&lt;/span&gt; #temp &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;DateIn, DateOut&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;VALUES&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;2012-10-10 9:38:45.757&#039;&lt;/span&gt;,null&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;INTO&lt;/span&gt; #temp &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;DateIn, DateOut&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;VALUES&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;2011-10-10 9:38:45.757&#039;&lt;/span&gt;,&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;2012-10-10 9:38:45.757&#039;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;INTO&lt;/span&gt; #temp &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;DateIn, DateOut&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;VALUES&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;null,&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;2011-10-10 9:38:45.757&#039;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;INTO&lt;/span&gt; #temp &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;DateIn, DateOut&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;VALUES&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;null,&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;2011-10-10 9:38:45.757&#039;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;INTO&lt;/span&gt; #temp &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;DateIn, DateOut&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;VALUES&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;2012-10-10 9:38:45.757&#039;&lt;/span&gt;,null&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;INTO&lt;/span&gt; #temp &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;DateIn, DateOut&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;VALUES&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;2011-10-10 9:38:45.757&#039;&lt;/span&gt;,&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;2012-10-10 9:38:45.757&#039;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;INTO&lt;/span&gt; #temp &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;DateIn, DateOut&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;VALUES&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;2009-10-10 9:38:45.757&#039;&lt;/span&gt;,&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;2010-10-10 9:38:45.757&#039;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;INSERT&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;INTO&lt;/span&gt; #temp &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;DateIn, DateOut&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;VALUES&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;2009-10-10 9:38:45.757&#039;&lt;/span&gt;,&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;2010-10-10 9:38:45.757&#039;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb57594&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt; &lt;/p&gt;

&lt;p&gt;Then the result would look like the below.&lt;/p&gt;

&lt;div class=&quot;tables&quot;&gt;
&lt;table&gt;
&lt;tr&gt;&lt;th&gt;Year&lt;/th&gt;&lt;th&gt;NumberIn&lt;/th&gt;&lt;th&gt;NumberOut&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;2009&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;NULL&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;2011&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;2012&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;

&lt;p&gt;See how we are missing a year? The user won&#039;t be happy if he has to guess the year.&lt;/p&gt;

&lt;p&gt;The solution is simple.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb38684&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color: #FF00FF;&quot;&gt;coalesce&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;DateInData.&lt;span style=&quot;color: #FF00FF;&quot;&gt;YEAR&lt;/span&gt;, DateOutData.&lt;span style=&quot;color: #FF00FF;&quot;&gt;Year&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color: #FF00FF;&quot;&gt;COALESCE&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;numberin,&lt;span style=&quot;color: #000;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; numberin, &lt;span style=&quot;color: #FF00FF;&quot;&gt;COALESCE&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;numberout,&lt;span style=&quot;color: #000;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; numberout&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;FROM&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color: #FF00FF;&quot;&gt;YEAR&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;datein&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: #FF00FF;&quot;&gt;YEAR&lt;/span&gt;, &lt;span style=&quot;color: #FF00FF;&quot;&gt;COUNT&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;*&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; numberin &lt;span style=&quot;color: #0000FF;&quot;&gt;FROM&lt;/span&gt; #temp &lt;span style=&quot;color: #0000FF;&quot;&gt;GROUP&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;BY&lt;/span&gt; &lt;span style=&quot;color: #FF00FF;&quot;&gt;YEAR&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;datein&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;HAVING&lt;/span&gt; &lt;span style=&quot;color: #FF00FF;&quot;&gt;YEAR&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;datein&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;IS&lt;/span&gt; NOT NULL&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; DateInData&lt;br /&gt;&amp;nbsp; &amp;nbsp; FULL OUTER JOIN &lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color: #FF00FF;&quot;&gt;YEAR&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;dateout&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; &lt;span style=&quot;color: #FF00FF;&quot;&gt;YEAR&lt;/span&gt;, &lt;span style=&quot;color: #FF00FF;&quot;&gt;COUNT&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;*&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; numberout &lt;span style=&quot;color: #0000FF;&quot;&gt;FROM&lt;/span&gt; #temp &lt;span style=&quot;color: #0000FF;&quot;&gt;GROUP&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;BY&lt;/span&gt; &lt;span style=&quot;color: #FF00FF;&quot;&gt;YEAR&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;dateout&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;HAVING&lt;/span&gt; &lt;span style=&quot;color: #FF00FF;&quot;&gt;YEAR&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;dateout&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;IS&lt;/span&gt; NOT NULL&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;AS&lt;/span&gt; DateOutData&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;ON&lt;/span&gt; DateInData.&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #FF00FF;&quot;&gt;YEAR&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt; = DateOutData.&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #FF00FF;&quot;&gt;YEAR&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb80224&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I added the coalesce(dateindata.year, dateoutdata.year) in other words if the year of dateindata is null then go for the year that is in dateoutdata.&lt;/p&gt;

&lt;p&gt;And now the user no longer has to guess the year.&lt;/p&gt;

&lt;div class=&quot;tables&quot;&gt;
&lt;table&gt;
&lt;tr&gt;&lt;th&gt;Year&lt;/th&gt;&lt;th&gt;NumberIn&lt;/th&gt;&lt;th&gt;NumberOut&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;2009&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;2010&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;2011&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;2012&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;


&lt;p&gt;So sometimes you just have to look at your table definition before making assumptions because your assumptions might be wrong, one would think that there is always a datein when there is a dateout but one can not be sure.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/MSSQLServer/full-outer-join-requires-some&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>I don't need Full outer joins all that often. So when I do I have to think on what it will return me. </p>

<p>You can go to <a href="http://en.wikipedia.org/wiki/Join_(SQL)#Full_outer_join">wikipedia</a> to find the full explanation on full outer joins if you want to.</p>

<p>But in short it is this.</p>

<blockquote><p>Conceptually, a full outer join combines the effect of applying both left and right outer joins. Where records in the FULL OUTER JOINed tables do not match, the result set will have NULL values for every column of the table that lacks a matching row. For those records that do match, a single row will be produced in the result set (containing fields populated from both tables).<br />
For example, this allows us to see each employee who is in a department and each department that has an employee, but also see each employee who is not part of a department and each department which doesn't have an employee.</p></blockquote>

<p>What I needed was to combine the result of two queries where I did a sum by year and join on the year. </p>

<p>Here is the testdate.</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb16263'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb16263','cb18492'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb16263" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> #temp </li><li style="" class="li2"><span style="color: #808080;">&#40;</span></li><li style="" class="li1">&nbsp; &nbsp; Id <span style="color: #0000FF;">INT</span> <span style="color: #0000FF;">IDENTITY</span><span style="color: #808080;">&#40;</span><span style="color: #000;">1</span>,<span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">PRIMARY</span> <span style="color: #0000FF;">KEY</span> NOT NULL</li><li style="" class="li2">&nbsp; &nbsp; , DateIn <span style="color: #0000FF;">DATETIME</span> NULL</li><li style="" class="li1">&nbsp; &nbsp; , DateOut <span style="color: #0000FF;">DATETIME</span> NULL</li><li style="" class="li2"><span style="color: #808080;">&#41;</span></li><li style="" class="li1"><span style="color: #0000FF;">GO</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> #temp <span style="color: #808080;">&#40;</span>DateIn, DateOut<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'2012-10-10 9:38:45.757'</span>,null<span style="color: #808080;">&#41;</span> </li><li style="" class="li2"><span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> #temp <span style="color: #808080;">&#40;</span>DateIn, DateOut<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'2011-10-10 9:38:45.757'</span>,<span style="color: #FF0000;">'2012-10-10 9:38:45.757'</span><span style="color: #808080;">&#41;</span> </li><li style="" class="li1"><span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> #temp <span style="color: #808080;">&#40;</span>DateIn, DateOut<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'2010-10-10 9:38:45.757'</span>,<span style="color: #FF0000;">'2011-10-10 9:38:45.757'</span><span style="color: #808080;">&#41;</span> </li><li style="" class="li2"><span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> #temp <span style="color: #808080;">&#40;</span>DateIn, DateOut<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'2010-10-10 9:38:45.757'</span>,<span style="color: #FF0000;">'2011-10-10 9:38:45.757'</span><span style="color: #808080;">&#41;</span> </li><li style="" class="li1"><span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> #temp <span style="color: #808080;">&#40;</span>DateIn, DateOut<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'2012-10-10 9:38:45.757'</span>,null<span style="color: #808080;">&#41;</span> </li><li style="" class="li2"><span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> #temp <span style="color: #808080;">&#40;</span>DateIn, DateOut<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'2011-10-10 9:38:45.757'</span>,<span style="color: #FF0000;">'2012-10-10 9:38:45.757'</span><span style="color: #808080;">&#41;</span> </li><li style="" class="li1"><span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> #temp <span style="color: #808080;">&#40;</span>DateIn, DateOut<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'2009-10-10 9:38:45.757'</span>,<span style="color: #FF0000;">'2010-10-10 9:38:45.757'</span><span style="color: #808080;">&#41;</span> </li><li style="" class="li2"><span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> #temp <span style="color: #808080;">&#40;</span>DateIn, DateOut<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'2009-10-10 9:38:45.757'</span>,<span style="color: #FF0000;">'2010-10-10 9:38:45.757'</span><span style="color: #808080;">&#41;</span> </li><li style="" class="li1"><span style="color: #0000FF;">GO</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #0000FF;">SELECT</span> Id, datein, dateout <span style="color: #0000FF;">FROM</span> #temp</li><li style="" class="li2"><span style="color: #0000FF;">GO</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #0000FF;">DROP</span> <span style="color: #0000FF;">TABLE</span> #temp</li><li style="" class="li1"><span style="color: #0000FF;">GO</span></li></ol></div><div id="cb18492" style="display: none; color: red;"></div></div></div>

<p>And the desired result was something like this.</p>

<div class="tables">
<table>
<tr><th>Year</th><th>NumberIn</th><th>NumberOut</th></tr>
<tr><td>2009</td><td>2</td><td>0</td></tr>
<tr><td>2010</td><td>2</td><td>2</td></tr>
<tr><td>2011</td><td>2</td><td>2</td></tr>
<tr><td>2012</td><td>2</td><td>2</td></tr>
</table>
</div>

<p>My first query was this.</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb45213'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb45213','cb28461'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb45213" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">SELECT</span> DateInData.<span style="color: #FF00FF;">YEAR</span>, <span style="color: #FF00FF;">COALESCE</span><span style="color: #808080;">&#40;</span>numberin,<span style="color: #000;">0</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> numberin, <span style="color: #FF00FF;">COALESCE</span><span style="color: #808080;">&#40;</span>numberout,<span style="color: #000;">0</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> numberout</li><li style="" class="li2"><span style="color: #0000FF;">FROM</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #FF00FF;">YEAR</span><span style="color: #808080;">&#40;</span>datein<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #FF00FF;">YEAR</span>, <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span>*<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> numberin <span style="color: #0000FF;">FROM</span> #temp <span style="color: #0000FF;">GROUP</span> <span style="color: #0000FF;">BY</span> <span style="color: #FF00FF;">YEAR</span><span style="color: #808080;">&#40;</span>datein<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">HAVING</span> <span style="color: #FF00FF;">YEAR</span><span style="color: #808080;">&#40;</span>datein<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">IS</span> NOT NULL<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> DateInData</li><li style="" class="li2">&nbsp; &nbsp; FULL OUTER JOIN </li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #FF00FF;">YEAR</span><span style="color: #808080;">&#40;</span>dateout<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #FF00FF;">YEAR</span>, <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span>*<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> numberout <span style="color: #0000FF;">FROM</span> #temp <span style="color: #0000FF;">GROUP</span> <span style="color: #0000FF;">BY</span> <span style="color: #FF00FF;">YEAR</span><span style="color: #808080;">&#40;</span>dateout<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">HAVING</span> <span style="color: #FF00FF;">YEAR</span><span style="color: #808080;">&#40;</span>dateout<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">IS</span> NOT NULL<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> DateOutData</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0000FF;">ON</span> DateInData.<span style="color: #808080;">&#91;</span><span style="color: #FF00FF;">YEAR</span><span style="color: #808080;">&#93;</span> = DateOutData.<span style="color: #808080;">&#91;</span><span style="color: #FF00FF;">YEAR</span><span style="color: #808080;">&#93;</span></li><li style="" class="li1"><span style="color: #0000FF;">GO</span></li></ol></div><div id="cb28461" style="display: none; color: red;"></div></div></div>

<p>And hooray, that gives the correct results. So lets move on.</p>

<p>Hold on. In the above I am assuming that datein will always be filled in. But my table definition says it is not a mandatory field.</p>

<p>So what would happen if I had the following data in my table.</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb23779'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb23779','cb54930'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb23779" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> #temp <span style="color: #808080;">&#40;</span>DateIn, DateOut<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'2012-10-10 9:38:45.757'</span>,null<span style="color: #808080;">&#41;</span> </li><li style="" class="li2"><span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> #temp <span style="color: #808080;">&#40;</span>DateIn, DateOut<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'2011-10-10 9:38:45.757'</span>,<span style="color: #FF0000;">'2012-10-10 9:38:45.757'</span><span style="color: #808080;">&#41;</span> </li><li style="" class="li1"><span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> #temp <span style="color: #808080;">&#40;</span>DateIn, DateOut<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span>null,<span style="color: #FF0000;">'2011-10-10 9:38:45.757'</span><span style="color: #808080;">&#41;</span> </li><li style="" class="li2"><span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> #temp <span style="color: #808080;">&#40;</span>DateIn, DateOut<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span>null,<span style="color: #FF0000;">'2011-10-10 9:38:45.757'</span><span style="color: #808080;">&#41;</span> </li><li style="" class="li1"><span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> #temp <span style="color: #808080;">&#40;</span>DateIn, DateOut<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'2012-10-10 9:38:45.757'</span>,null<span style="color: #808080;">&#41;</span> </li><li style="" class="li2"><span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> #temp <span style="color: #808080;">&#40;</span>DateIn, DateOut<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'2011-10-10 9:38:45.757'</span>,<span style="color: #FF0000;">'2012-10-10 9:38:45.757'</span><span style="color: #808080;">&#41;</span> </li><li style="" class="li1"><span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> #temp <span style="color: #808080;">&#40;</span>DateIn, DateOut<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'2009-10-10 9:38:45.757'</span>,<span style="color: #FF0000;">'2010-10-10 9:38:45.757'</span><span style="color: #808080;">&#41;</span> </li><li style="" class="li2"><span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> #temp <span style="color: #808080;">&#40;</span>DateIn, DateOut<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'2009-10-10 9:38:45.757'</span>,<span style="color: #FF0000;">'2010-10-10 9:38:45.757'</span><span style="color: #808080;">&#41;</span> </li><li style="" class="li1"><span style="color: #0000FF;">GO</span></li></ol></div><div id="cb54930" style="display: none; color: red;"></div></div></div><p> </p>

<p>Then the result would look like the below.</p>

<div class="tables">
<table>
<tr><th>Year</th><th>NumberIn</th><th>NumberOut</th></tr>
<tr><td>2009</td><td>2</td><td>0</td></tr>
<tr><td>NULL</td><td>0</td><td>2</td></tr>
<tr><td>2011</td><td>2</td><td>2</td></tr>
<tr><td>2012</td><td>2</td><td>2</td></tr>
</table>
</div>

<p>See how we are missing a year? The user won't be happy if he has to guess the year.</p>

<p>The solution is simple.</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb59545'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb59545','cb91082'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb59545" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">SELECT</span> <span style="color: #FF00FF;">coalesce</span><span style="color: #808080;">&#40;</span>DateInData.<span style="color: #FF00FF;">YEAR</span>, DateOutData.<span style="color: #FF00FF;">Year</span><span style="color: #808080;">&#41;</span>, <span style="color: #FF00FF;">COALESCE</span><span style="color: #808080;">&#40;</span>numberin,<span style="color: #000;">0</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> numberin, <span style="color: #FF00FF;">COALESCE</span><span style="color: #808080;">&#40;</span>numberout,<span style="color: #000;">0</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> numberout</li><li style="" class="li2"><span style="color: #0000FF;">FROM</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #FF00FF;">YEAR</span><span style="color: #808080;">&#40;</span>datein<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #FF00FF;">YEAR</span>, <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span>*<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> numberin <span style="color: #0000FF;">FROM</span> #temp <span style="color: #0000FF;">GROUP</span> <span style="color: #0000FF;">BY</span> <span style="color: #FF00FF;">YEAR</span><span style="color: #808080;">&#40;</span>datein<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">HAVING</span> <span style="color: #FF00FF;">YEAR</span><span style="color: #808080;">&#40;</span>datein<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">IS</span> NOT NULL<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> DateInData</li><li style="" class="li2">&nbsp; &nbsp; FULL OUTER JOIN </li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #FF00FF;">YEAR</span><span style="color: #808080;">&#40;</span>dateout<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #FF00FF;">YEAR</span>, <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span>*<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> numberout <span style="color: #0000FF;">FROM</span> #temp <span style="color: #0000FF;">GROUP</span> <span style="color: #0000FF;">BY</span> <span style="color: #FF00FF;">YEAR</span><span style="color: #808080;">&#40;</span>dateout<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">HAVING</span> <span style="color: #FF00FF;">YEAR</span><span style="color: #808080;">&#40;</span>dateout<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">IS</span> NOT NULL<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> DateOutData</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0000FF;">ON</span> DateInData.<span style="color: #808080;">&#91;</span><span style="color: #FF00FF;">YEAR</span><span style="color: #808080;">&#93;</span> = DateOutData.<span style="color: #808080;">&#91;</span><span style="color: #FF00FF;">YEAR</span><span style="color: #808080;">&#93;</span></li><li style="" class="li1"><span style="color: #0000FF;">GO</span></li></ol></div><div id="cb91082" style="display: none; color: red;"></div></div></div>

<p>I added the coalesce(dateindata.year, dateoutdata.year) in other words if the year of dateindata is null then go for the year that is in dateoutdata.</p>

<p>And now the user no longer has to guess the year.</p>

<div class="tables">
<table>
<tr><th>Year</th><th>NumberIn</th><th>NumberOut</th></tr>
<tr><td>2009</td><td>2</td><td>0</td></tr>
<tr><td>2010</td><td>0</td><td>2</td></tr>
<tr><td>2011</td><td>2</td><td>2</td></tr>
<tr><td>2012</td><td>2</td><td>2</td></tr>
</table>
</div>


<p>So sometimes you just have to look at your table definition before making assumptions because your assumptions might be wrong, one would think that there is always a datein when there is a dateout but one can not be sure.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/MSSQLServer/full-outer-join-requires-some">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/MSSQLServer/full-outer-join-requires-some#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=1856</wfw:commentRss>
		</item>
				<item>
			<title>SQLCop is now available via chocolatey</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/sqlcop-is-now-available-via</link>
			<pubDate>Wed, 16 Nov 2011 08:35:00 +0000</pubDate>			<dc:creator>Christiaan Baes (chrissie1)</dc:creator>
			<category domain="main">Microsoft SQL Server Admin</category>			<guid isPermaLink="false">1481@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;Here is the definition of &lt;a href=&quot;http://blogs.lessthandot.com/index.php/DesktopDev/MSTech/chocolatey-apt-get-for-windows?highlight=chocolatey&amp;amp;sentence=&quot;&gt;chocolatey&lt;/a&gt; as stated on the &lt;a href=&quot;http://chocolatey.org&quot;&gt;chocolatey.org&lt;/a&gt; website.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;Chocolatey NuGet is a Machine Package Manager, somewhat like apt-get, but built with windows in mind.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Chocolatey can be easily installed.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;To install chocolatey now, open a powershell prompt (execution policy needs to be unrestricted - Set-ExecutionPolicy Unrestricted), paste the following and type Enter:&lt;/p&gt;

&lt;p&gt;PS:\&gt; iex ((new-object net.webclient).DownloadString(&quot;http://bit.ly/psChocInstall&quot;))&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And Chocolatey also has &lt;a href=&quot;http://blogs.lessthandot.com/index.php/DesktopDev/MSTech/chocolatey-gui?highlight=chocolatey&amp;amp;sentence=&quot;&gt;a GUI&lt;/a&gt; if you like those kinds of things. Yeah I wrote that GUI, sorry.&lt;/p&gt;

&lt;p&gt;And now I added &lt;a href=&quot;http://chocolatey.org/packages/sqlcop&quot;&gt;sqlcop to chocolatey&lt;/a&gt; which makes it dead easy to install.&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/users/chrissie1/chocolatey/sqlcopchocolatey1.png?mtime=1321439578&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/users/chrissie1/chocolatey/sqlcopchocolatey1.png?mtime=1321439578&quot; width=&quot;1039&quot; height=&quot;629&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;Just type &lt;code class=&quot;codespan&quot;&gt;cinst sqlcop&lt;/code&gt; in your favorite command prompt or use the GUI and sqlcop will be there for you. It will also place a shortcut on your desktop for you to have easy access to sqlcop.&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/users/chrissie1/chocolatey/sqlcopchocolatey2.png?mtime=1321439592&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/users/chrissie1/chocolatey/sqlcopchocolatey2.png?mtime=1321439592&quot; width=&quot;430&quot; height=&quot;374&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;So now you have no more excuse not to install chocolatey and sqlcop.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DesktopDev/MSTech/making-a-chocolatey-package?highlight=chocolatey&amp;amp;sentence=&quot;&gt;Making a chocolatey package&lt;/a&gt; is easy BTW.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/sqlcop-is-now-available-via&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>Here is the definition of <a href="http://blogs.lessthandot.com/index.php/DesktopDev/MSTech/chocolatey-apt-get-for-windows?highlight=chocolatey&amp;sentence=">chocolatey</a> as stated on the <a href="http://chocolatey.org">chocolatey.org</a> website.</p>

<blockquote><p>Chocolatey NuGet is a Machine Package Manager, somewhat like apt-get, but built with windows in mind.</p></blockquote>

<p>Chocolatey can be easily installed.</p>

<blockquote><p>To install chocolatey now, open a powershell prompt (execution policy needs to be unrestricted - Set-ExecutionPolicy Unrestricted), paste the following and type Enter:</p>

<p>PS:\> iex ((new-object net.webclient).DownloadString("http://bit.ly/psChocInstall"))</p>
</blockquote>

<p>And Chocolatey also has <a href="http://blogs.lessthandot.com/index.php/DesktopDev/MSTech/chocolatey-gui?highlight=chocolatey&amp;sentence=">a GUI</a> if you like those kinds of things. Yeah I wrote that GUI, sorry.</p>

<p>And now I added <a href="http://chocolatey.org/packages/sqlcop">sqlcop to chocolatey</a> which makes it dead easy to install.</p>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/users/chrissie1/chocolatey/sqlcopchocolatey1.png?mtime=1321439578"><img alt="" src="http://blogs.lessthandot.com/media/users/chrissie1/chocolatey/sqlcopchocolatey1.png?mtime=1321439578" width="1039" height="629" /></a></div>

<p>Just type <code class="codespan">cinst sqlcop</code> in your favorite command prompt or use the GUI and sqlcop will be there for you. It will also place a shortcut on your desktop for you to have easy access to sqlcop.</p>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/users/chrissie1/chocolatey/sqlcopchocolatey2.png?mtime=1321439592"><img alt="" src="http://blogs.lessthandot.com/media/users/chrissie1/chocolatey/sqlcopchocolatey2.png?mtime=1321439592" width="430" height="374" /></a></div>

<p>So now you have no more excuse not to install chocolatey and sqlcop.</p>

<p><a href="http://blogs.lessthandot.com/index.php/DesktopDev/MSTech/making-a-chocolatey-package?highlight=chocolatey&amp;sentence=">Making a chocolatey package</a> is easy BTW.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/sqlcop-is-now-available-via">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/sqlcop-is-now-available-via#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=1481</wfw:commentRss>
		</item>
				<item>
			<title>Installing SQL Server Express 2008 Management Studio</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/installing-sql-server-express-2008-manag</link>
			<pubDate>Mon, 02 Nov 2009 08:11:16 +0000</pubDate>			<dc:creator>Christiaan Baes (chrissie1)</dc:creator>
			<category domain="main">Data Modelling &amp; Design</category>			<guid isPermaLink="false">646@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;Well now that we have the &lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/installin-sql-server-express-2008-is-eas&quot;&gt;engine installed&lt;/a&gt;. We sometimes also want the GUI tools to go with it.&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;MT_red&quot;&gt;I would recommend a reboot however. That&#039;s what made it work for me.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;Let&#039;s go to the &lt;a href=&quot;http://www.microsoft.com/express/sql/download/&quot;&gt;Microsoft download page&lt;/a&gt; again and find the install button.&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;img src=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/wpiinstaller/wpiinstaller5.png&quot; alt=&quot;&quot; title=&quot;&quot; width=&quot;639&quot; height=&quot;400&quot; /&gt;&lt;/div&gt;&lt;p&gt; &lt;/p&gt;

&lt;p&gt;Click install and then you get this, since we already installed the web platform installer in a previous post:&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;img src=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/wpiinstaller/wpiinstaller6.png&quot; alt=&quot;&quot; title=&quot;&quot; width=&quot;769&quot; height=&quot;568&quot; /&gt;&lt;/div&gt;

&lt;p&gt;Which will present you with this:&lt;br /&gt;
 &lt;/p&gt;
&lt;div class=&quot;image_block&quot;&gt;&lt;img src=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/wpiinstaller/wpiinstaller4.png&quot; alt=&quot;&quot; title=&quot;&quot; width=&quot;363&quot; height=&quot;353&quot; /&gt;&lt;/div&gt;&lt;p&gt; &lt;/p&gt;

&lt;p&gt;I&#039;m sorry to say it doesn&#039;t install that for me. But you can &lt;a href=&quot;http://www.microsoft.com/downloads/thankyou.aspx?familyId=fbee1648-7106-44a7-9649-6d9f6d58056e&amp;amp;displayLang=en&quot;&gt;download it here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Many minutes later.&lt;/p&gt;

&lt;p&gt;We can install Management studio.&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;img src=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/wpiinstaller/wpiinstaller7.png&quot; alt=&quot;&quot; title=&quot;&quot; width=&quot;768&quot; height=&quot;668&quot; /&gt;&lt;/div&gt;&lt;p&gt; &lt;/p&gt;

&lt;p&gt;And then I get this window.&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;&lt;div class=&quot;image_block&quot;&gt;&lt;img src=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/wpiinstaller/wpiinstaller8.png&quot; alt=&quot;&quot; title=&quot;&quot; width=&quot;602&quot; height=&quot;298&quot; /&gt;&lt;/div&gt;&lt;p&gt; &lt;/p&gt;

&lt;p&gt;So I click check run program anyway, we will do the update later.&lt;/p&gt;

&lt;p&gt;BTW The update can be found here:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.microsoft.com/downloads/details.aspx?FamilyID=66ab3dbb-bf3e-4f46-9559-ccc6a4f9dc19&amp;amp;displaylang=en&quot;&gt;http://www.microsoft.com/downloads/details.aspx?FamilyID=66ab3dbb-bf3e-4f46-9559-ccc6a4f9dc19&amp;amp;displaylang=en&lt;/a&gt;&lt;/p&gt;


&lt;p&gt;And voila, I&#039;m done. Not the best of User Experiences I ever had and in the end not much better then what it used to be.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/installing-sql-server-express-2008-manag&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>Well now that we have the <a href="http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/installin-sql-server-express-2008-is-eas">engine installed</a>. We sometimes also want the GUI tools to go with it.</p>

<p><span class="MT_red">I would recommend a reboot however. That's what made it work for me.</span></p>

<p>Let's go to the <a href="http://www.microsoft.com/express/sql/download/">Microsoft download page</a> again and find the install button.</p>

<div class="image_block"><img src="http://blogs.lessthandot.com/media/blogs/DataMgmt/wpiinstaller/wpiinstaller5.png" alt="" title="" width="639" height="400" /></div><p> </p>

<p>Click install and then you get this, since we already installed the web platform installer in a previous post:</p>

<div class="image_block"><img src="http://blogs.lessthandot.com/media/blogs/DataMgmt/wpiinstaller/wpiinstaller6.png" alt="" title="" width="769" height="568" /></div>

<p>Which will present you with this:<br />
 </p>
<div class="image_block"><img src="http://blogs.lessthandot.com/media/blogs/DataMgmt/wpiinstaller/wpiinstaller4.png" alt="" title="" width="363" height="353" /></div><p> </p>

<p>I'm sorry to say it doesn't install that for me. But you can <a href="http://www.microsoft.com/downloads/thankyou.aspx?familyId=fbee1648-7106-44a7-9649-6d9f6d58056e&amp;displayLang=en">download it here</a>.</p>

<p>Many minutes later.</p>

<p>We can install Management studio.</p>

<div class="image_block"><img src="http://blogs.lessthandot.com/media/blogs/DataMgmt/wpiinstaller/wpiinstaller7.png" alt="" title="" width="768" height="668" /></div><p> </p>

<p>And then I get this window.</p>

<p> </p><div class="image_block"><img src="http://blogs.lessthandot.com/media/blogs/DataMgmt/wpiinstaller/wpiinstaller8.png" alt="" title="" width="602" height="298" /></div><p> </p>

<p>So I click check run program anyway, we will do the update later.</p>

<p>BTW The update can be found here:</p>

<p><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=66ab3dbb-bf3e-4f46-9559-ccc6a4f9dc19&amp;displaylang=en">http://www.microsoft.com/downloads/details.aspx?FamilyID=66ab3dbb-bf3e-4f46-9559-ccc6a4f9dc19&amp;displaylang=en</a></p>


<p>And voila, I'm done. Not the best of User Experiences I ever had and in the end not much better then what it used to be.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/installing-sql-server-express-2008-manag">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/installing-sql-server-express-2008-manag#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=646</wfw:commentRss>
		</item>
				<item>
			<title>Installing sql server express 2008 is easier than it used to be</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/installin-sql-server-express-2008-is-eas</link>
			<pubDate>Mon, 02 Nov 2009 06:00:15 +0000</pubDate>			<dc:creator>Christiaan Baes (chrissie1)</dc:creator>
			<category domain="main">Data Modelling &amp; Design</category>			<guid isPermaLink="false">645@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;I remember having a hard time &lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/installing-sql-server-2008-express-on-wi?highlight=express&amp;amp;sentence=&quot;&gt;installing sql server express 2008 on windows XP&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So today I had to install it again on win7 I looked for the download and found it on the &lt;a href=&quot;http://www.microsoft.com/express/sql/download/&quot;&gt;microsoft website&lt;/a&gt;. I was prepared for some more pain and a long wait like I was used to. But it started by installing the web platform installer. &lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;img src=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/wpiinstaller/wpiinstaller3.png&quot; alt=&quot;&quot; title=&quot;&quot; width=&quot;945&quot; height=&quot;637&quot; /&gt;&lt;/div&gt;&lt;p&gt; &lt;/p&gt;

&lt;p&gt;So I downloaded that and installed it (not something that works by itself, it needs an extra click or two. &lt;/p&gt;

&lt;p&gt;And then I could click on the &quot;Finish your installation&quot; thing. Which showed me this. &lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;img src=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/wpiinstaller/wpiinstaller4.png&quot; alt=&quot;&quot; title=&quot;&quot; width=&quot;363&quot; height=&quot;353&quot; /&gt;&lt;/div&gt;&lt;p&gt; &lt;/p&gt;

&lt;p&gt;Which was telling me to click Web platform installer and then Ok. Easy&lt;/p&gt;

&lt;p&gt;After that, I could go on with installing SQL Server 2008 Express. Because as soon as the web platform installer launched it showed me this:&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;img src=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/wpiinstaller/wpiinstaller1.png&quot; alt=&quot;&quot; title=&quot;&quot; width=&quot;767&quot; height=&quot;570&quot; /&gt;&lt;/div&gt;
&lt;p&gt; &lt;br /&gt;
Just click Install, and watch the progressbars move.&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;img src=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/wpiinstaller/wpiinstaller2.png&quot; alt=&quot;&quot; title=&quot;&quot; width=&quot;700&quot; height=&quot;480&quot; /&gt;&lt;/div&gt;

&lt;p&gt;And after a short while it said it was installed. No reboots or anything. &lt;/p&gt;

&lt;p&gt;Of course I&#039;m sure that Win7 has all the prerequisites that XP hasn&#039;t but still I got SQL server 2008 Express installed in less than 20 minutes. &lt;/p&gt;

&lt;p&gt;I like it.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/installin-sql-server-express-2008-is-eas&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>I remember having a hard time <a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/installing-sql-server-2008-express-on-wi?highlight=express&amp;sentence=">installing sql server express 2008 on windows XP</a>.</p>

<p>So today I had to install it again on win7 I looked for the download and found it on the <a href="http://www.microsoft.com/express/sql/download/">microsoft website</a>. I was prepared for some more pain and a long wait like I was used to. But it started by installing the web platform installer. </p>

<div class="image_block"><img src="http://blogs.lessthandot.com/media/blogs/DataMgmt/wpiinstaller/wpiinstaller3.png" alt="" title="" width="945" height="637" /></div><p> </p>

<p>So I downloaded that and installed it (not something that works by itself, it needs an extra click or two. </p>

<p>And then I could click on the "Finish your installation" thing. Which showed me this. </p>

<div class="image_block"><img src="http://blogs.lessthandot.com/media/blogs/DataMgmt/wpiinstaller/wpiinstaller4.png" alt="" title="" width="363" height="353" /></div><p> </p>

<p>Which was telling me to click Web platform installer and then Ok. Easy</p>

<p>After that, I could go on with installing SQL Server 2008 Express. Because as soon as the web platform installer launched it showed me this:</p>

<div class="image_block"><img src="http://blogs.lessthandot.com/media/blogs/DataMgmt/wpiinstaller/wpiinstaller1.png" alt="" title="" width="767" height="570" /></div>
<p> <br />
Just click Install, and watch the progressbars move.</p>

<div class="image_block"><img src="http://blogs.lessthandot.com/media/blogs/DataMgmt/wpiinstaller/wpiinstaller2.png" alt="" title="" width="700" height="480" /></div>

<p>And after a short while it said it was installed. No reboots or anything. </p>

<p>Of course I'm sure that Win7 has all the prerequisites that XP hasn't but still I got SQL server 2008 Express installed in less than 20 minutes. </p>

<p>I like it.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/installin-sql-server-express-2008-is-eas">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/installin-sql-server-express-2008-is-eas#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=645</wfw:commentRss>
		</item>
				<item>
			<title>Installing SQL Server 2008 express on Windows XP SP 2 without reading the manual</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/installing-sql-server-2008-express-on-wi</link>
			<pubDate>Sun, 08 Feb 2009 16:11:51 +0000</pubDate>			<dc:creator>Christiaan Baes (chrissie1)</dc:creator>
			<category domain="main">Microsoft SQL Server Admin</category>			<guid isPermaLink="false">330@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;Today I was going to write a blogpost about persisting the simple domainmodel using Nhibernate and Fluent Nhibernate (I will have to write this later). It turned out to be quite and adventure. First I finaly installed &lt;a href=&quot;http://www.jetbrains.com/resharper/&quot;&gt;R#&lt;/a&gt; on this machine I&#039;ve been having the license since last octobre just haven&#039;t used it yet on this or any other machine. That installation was pretty painless I must say.&lt;/p&gt;

&lt;p&gt;Then I needed to install some kind of database. And I like shiny and new so I installed (or wanted to install) &lt;a href=&quot;http://www.microsoft.com/express/sql/download/&quot;&gt;SQL server express 2008&lt;/a&gt; on my Windows XP SP2 which is fully supported on this OS. It turned out to be a 5 hour plus ordeal and installing one program after the other. But lets not forget it&#039;s free. So I&#039;m not complaining just venting. First thing it said (well after a couple of minutes of unzipping it&#039;s install files in some guid folder) was that I needed the &lt;a href=&quot;http://www.microsoft.com/downloads/details.aspx?familyid=ab99342f-5d1a-413d-8319-81da479ab0d7&amp;amp;displaylang=en&quot;&gt;3.5 SP1 framework&lt;/a&gt;. Silly me only had 3.5. So I did that and restarted. At that moment I lost my first version of the blogpost. My bad. I only copied it to the clipboard.&lt;/p&gt;

&lt;p&gt;Then I tried to install SQL Server Express again. And after deflating the files again in another GUID folder. It told me I should install &lt;a href=&quot;http://www.microsoft.com/downloadS/details.aspx?familyid=5A58B56F-60B6-4412-95B9-54D056D6F9F4&amp;amp;displaylang=en#filelist&quot;&gt;Windows installer 4.5&lt;/a&gt;. Which of course I did. &lt;/p&gt;

&lt;p&gt;Another restart later. I doubleclicked the SQL Server Express 2008 installer again and this time it actually started installing (I wonder what happened to the just_install_and_stop_nagging_me_button, I really miss that button). But no such luck. After the second next it said I had to install powershell for windows and the buttons back and next were disabled so after installing &lt;a href=&quot;http://www.microsoft.com/downloads/thankyou.aspx?familyId=6ccb7e0d-8f1d-4b97-a397-47bcc8ba3806&amp;amp;displayLang=en&amp;amp;hash=Eo0%2fiCVc0%2bajjm3KEUaYpJi%2fzkkLfuYY1rGRI6sPyEhB7Z7hnfL6Tmfv92v6xehtaS5pH4BSyTXtYgabtj5NJQ%3d%3d&quot;&gt;Powershell&lt;/a&gt; I had to restart the SQL Server 2008 Express edition again. And It was happy now. So I clicked the Third next button and now it complained that I had the wrong version of Visual Studio 2008. I needed &lt;a href=&quot;http://www.microsoft.com/downloads/details.aspx?FamilyId=FBEE1648-7106-44A7-9649-6D9F6D58056E&amp;amp;displaylang=en&quot;&gt;SP1&lt;/a&gt; for that too. So I installed that in two goes. &lt;/p&gt;

&lt;p&gt;But not there yet. I got this errormessage.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;TITLE: Microsoft SQL Server 2008 Setup&lt;br /&gt;
------------------------------&lt;/p&gt;

&lt;p&gt;The following error has occurred:&lt;/p&gt;

&lt;p&gt;The Windows Installer service cannot update the system file c:\WINDOWS\system32\msxml6r.dll because the file is protected by Windows.  You may need to update your operating system for this program to work correctly. &lt;/p&gt;

&lt;p&gt;For help, click: &lt;a href=&quot;http://go.microsoft.com/fwlink?LinkID=20476&amp;amp;ProdName=Microsoft+SQL+Server&amp;amp;EvtSrc=setup.rll&amp;amp;EvtID=50000&amp;amp;ProdVer=10.0.1600.22&amp;amp;EvtType=0xF45F6601%25401201%25401&quot;&gt;http://go.microsoft.com/fwlink?LinkID=20476&amp;amp;ProdName=Microsoft+SQL+Server&amp;amp;EvtSrc=setup.rll&amp;amp;EvtID=50000&amp;amp;ProdVer=10.0.1600.22&amp;amp;EvtType=0xF45F6601%25401201%25401&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt;


&lt;p&gt;Which led me to this page&lt;/p&gt;


&lt;blockquote&gt;&lt;p&gt;Details&lt;br /&gt;
Product:&lt;br /&gt;
SQL Server&lt;br /&gt;
ID:&lt;br /&gt;
50000&lt;br /&gt;
Source:&lt;br /&gt;
setup.rll&lt;br /&gt;
Version:&lt;br /&gt;
10.0&lt;br /&gt;
Component:&lt;br /&gt;
SQL Server Native Client&lt;br /&gt;
Message:&lt;br /&gt;
A network error occurred while attempting to read from the file &#039;%.*ls&#039;.&lt;br /&gt;
&amp;#160; &amp;#160;&lt;br /&gt;
Explanation&lt;br /&gt;
An attempt was made to install (or update) SQL Server Native Client on a computer where SQL Server Native Client is already installed, and where the existing installation was from an MSI file that was not named sqlncli.msi.&lt;br /&gt;
&amp;#160; &amp;#160;&lt;br /&gt;
User Action&lt;br /&gt;
To resolve this error, uninstall the existing version of SQL Server Native Client. To prevent this error, do not install SQL Server Native Client from an MSI file that is not named sqlncli.msi.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt; &lt;/p&gt;

&lt;p&gt;Seriously. Are they trying to be funny? Would I ever install something that doesn&#039;t have the name sqlncli.msi? I don&#039;t think so.&lt;/p&gt;

&lt;p&gt;So I uninstelled the two native clients on my machine and tried to install again. And finaly it worked&lt;/p&gt;

&lt;p&gt;So after all this I have SQL server Express 2008 on my machine. What an adventure.&lt;/p&gt;

&lt;p&gt;Now back to our regular program.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/installing-sql-server-2008-express-on-wi&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>Today I was going to write a blogpost about persisting the simple domainmodel using Nhibernate and Fluent Nhibernate (I will have to write this later). It turned out to be quite and adventure. First I finaly installed <a href="http://www.jetbrains.com/resharper/">R#</a> on this machine I've been having the license since last octobre just haven't used it yet on this or any other machine. That installation was pretty painless I must say.</p>

<p>Then I needed to install some kind of database. And I like shiny and new so I installed (or wanted to install) <a href="http://www.microsoft.com/express/sql/download/">SQL server express 2008</a> on my Windows XP SP2 which is fully supported on this OS. It turned out to be a 5 hour plus ordeal and installing one program after the other. But lets not forget it's free. So I'm not complaining just venting. First thing it said (well after a couple of minutes of unzipping it's install files in some guid folder) was that I needed the <a href="http://www.microsoft.com/downloads/details.aspx?familyid=ab99342f-5d1a-413d-8319-81da479ab0d7&amp;displaylang=en">3.5 SP1 framework</a>. Silly me only had 3.5. So I did that and restarted. At that moment I lost my first version of the blogpost. My bad. I only copied it to the clipboard.</p>

<p>Then I tried to install SQL Server Express again. And after deflating the files again in another GUID folder. It told me I should install <a href="http://www.microsoft.com/downloadS/details.aspx?familyid=5A58B56F-60B6-4412-95B9-54D056D6F9F4&amp;displaylang=en#filelist">Windows installer 4.5</a>. Which of course I did. </p>

<p>Another restart later. I doubleclicked the SQL Server Express 2008 installer again and this time it actually started installing (I wonder what happened to the just_install_and_stop_nagging_me_button, I really miss that button). But no such luck. After the second next it said I had to install powershell for windows and the buttons back and next were disabled so after installing <a href="http://www.microsoft.com/downloads/thankyou.aspx?familyId=6ccb7e0d-8f1d-4b97-a397-47bcc8ba3806&amp;displayLang=en&amp;hash=Eo0%2fiCVc0%2bajjm3KEUaYpJi%2fzkkLfuYY1rGRI6sPyEhB7Z7hnfL6Tmfv92v6xehtaS5pH4BSyTXtYgabtj5NJQ%3d%3d">Powershell</a> I had to restart the SQL Server 2008 Express edition again. And It was happy now. So I clicked the Third next button and now it complained that I had the wrong version of Visual Studio 2008. I needed <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=FBEE1648-7106-44A7-9649-6D9F6D58056E&amp;displaylang=en">SP1</a> for that too. So I installed that in two goes. </p>

<p>But not there yet. I got this errormessage.</p>

<blockquote><p>TITLE: Microsoft SQL Server 2008 Setup<br />
------------------------------</p>

<p>The following error has occurred:</p>

<p>The Windows Installer service cannot update the system file c:\WINDOWS\system32\msxml6r.dll because the file is protected by Windows.  You may need to update your operating system for this program to work correctly. </p>

<p>For help, click: <a href="http://go.microsoft.com/fwlink?LinkID=20476&amp;ProdName=Microsoft+SQL+Server&amp;EvtSrc=setup.rll&amp;EvtID=50000&amp;ProdVer=10.0.1600.22&amp;EvtType=0xF45F6601%25401201%25401">http://go.microsoft.com/fwlink?LinkID=20476&amp;ProdName=Microsoft+SQL+Server&amp;EvtSrc=setup.rll&amp;EvtID=50000&amp;ProdVer=10.0.1600.22&amp;EvtType=0xF45F6601%25401201%25401</a></p></blockquote>


<p>Which led me to this page</p>


<blockquote><p>Details<br />
Product:<br />
SQL Server<br />
ID:<br />
50000<br />
Source:<br />
setup.rll<br />
Version:<br />
10.0<br />
Component:<br />
SQL Server Native Client<br />
Message:<br />
A network error occurred while attempting to read from the file '%.*ls'.<br />
&#160; &#160;<br />
Explanation<br />
An attempt was made to install (or update) SQL Server Native Client on a computer where SQL Server Native Client is already installed, and where the existing installation was from an MSI file that was not named sqlncli.msi.<br />
&#160; &#160;<br />
User Action<br />
To resolve this error, uninstall the existing version of SQL Server Native Client. To prevent this error, do not install SQL Server Native Client from an MSI file that is not named sqlncli.msi.</p></blockquote><p> </p>

<p>Seriously. Are they trying to be funny? Would I ever install something that doesn't have the name sqlncli.msi? I don't think so.</p>

<p>So I uninstelled the two native clients on my machine and tried to install again. And finaly it worked</p>

<p>So after all this I have SQL server Express 2008 on my machine. What an adventure.</p>

<p>Now back to our regular program.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/installing-sql-server-2008-express-on-wi">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/installing-sql-server-2008-express-on-wi#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=330</wfw:commentRss>
		</item>
				<item>
			<title>SQL server Linked server between 2005 64bits and a 2000 32 bits server.</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/sql-server-linked-server-between-2005-64</link>
			<pubDate>Fri, 09 Jan 2009 16:57:51 +0000</pubDate>			<dc:creator>Christiaan Baes (chrissie1)</dc:creator>
			<category domain="main">Microsoft SQL Server Admin</category>			<guid isPermaLink="false">288@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;Today I wanted to import the last bits of data from the old server. The new server is a 2005 64 bits SQL server and the old server is a 2000 32 bits. I&#039;m no DBA and everything is internal so I don&#039;t really care about service packs and I can&#039;t remember which has which allthough I&#039;m sure the 2000 box has the latest SP but since they aren&#039;t even connected to the internet updating isn&#039;t easy. &lt;/p&gt;

&lt;p&gt;So today I setup a linked server between the two. I used my desktop to connect to the new server and then setup the linked server. And surprise surprise it didn&#039;t work. This was more or less the error I got. &lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;OLE DB provider &quot;SQLNCLI&quot; for linked server &quot;servername&quot; returned message &quot;Communication link failure&quot;.&lt;br /&gt;
Msg 10054, Level 16, State 1, Line 0&lt;br /&gt;
TCP Provider: An existing connection was forcibly closed by the remote host.&lt;br /&gt;
Msg 18456, Level 14, State 1, Line 0&lt;br /&gt;
Login failed for user &#039;NT AUTHORITY\ANONYMOUS LOGON&#039;.&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;I actually never solved this problem. I just gave ANONYMOUS LOGON rights on the database and deleted it shortly after. It is internal remember. That solved that error message. On to the next error message.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;OLE DB provider &quot;SQLNCLI&quot; for linked server &quot;servername&quot; returned message &quot;Unspecified error&quot;.&lt;br /&gt;
OLE DB provider &quot;SQLNCLI&quot; for linked server &quot;servername&quot; returned message &quot;The stored procedure required to complete this operation could not be found on the server. Please contact your system administrator.&quot;.&lt;br /&gt;
Msg 7311, Level 16, State 2, Line 1&lt;br /&gt;
Cannot obtain the schema rowset &quot;DBSCHEMA_TABLES_INFO&quot; for OLE DB provider &quot;SQLNCLI&quot; for linked server &quot;servername&quot;. The provider supports the interface, but returns a failure code when it is used.&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;This one was solved by doing a google. And finding &lt;a href=&quot;http://blog.sqlauthority.com/2007/05/04/sql-server-fix-error-msg-7311-level-16-state-2-line-1-cannot-obtain-the-schema-rowset-dbschema_tables_info-for-ole-db-provider-sqlncli-for-linked-server-linkedservername/&quot;&gt;this&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;At the same time Ted (onpnt) gave me &lt;a href=&quot;http://blog.raffaeu.com/archive/2008/06/19/sql-2005-and-linked-server-cannot-obtain-the-schema-rowset.aspx&quot;&gt;this solution&lt;/a&gt; and he the asked why I hadn&#039;t told him it was a 64 bit 2005 and the 2000 was 32 bit. Well Ted you didn&#039;t ask ;-). So it&#039;s all Teds fault it took me more then an hour to figure this out. Well that&#039;s my story anyway. &lt;/p&gt;

&lt;p&gt;The solution is to create this procedure.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb81646&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;create&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;procedure&lt;/span&gt; &lt;span style=&quot;color: #AF0000;&quot;&gt;sp_tables_info_rowset_64&lt;/span&gt;&lt;br /&gt;@table_name &lt;span style=&quot;color: #0000FF;&quot;&gt;sysname&lt;/span&gt;,&lt;br /&gt;@table_schema &lt;span style=&quot;color: #0000FF;&quot;&gt;sysname&lt;/span&gt; = null,&lt;br /&gt;@table_type &lt;span style=&quot;color: #0000FF;&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000;&quot;&gt;255&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; = null&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;as&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;declare&lt;/span&gt; @&lt;span style=&quot;color: #0000FF;&quot;&gt;Result&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;set&lt;/span&gt; @&lt;span style=&quot;color: #0000FF;&quot;&gt;Result&lt;/span&gt; = &lt;span style=&quot;color: #000;&quot;&gt;0&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &lt;span style=&quot;color: #0000FF;&quot;&gt;exec&lt;/span&gt; @&lt;span style=&quot;color: #0000FF;&quot;&gt;Result&lt;/span&gt; = &lt;span style=&quot;color: #AF0000;&quot;&gt;sp_tables_info_rowset&lt;/span&gt; @table_name, @table_schema, @table_type&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb31694&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;  &lt;br /&gt;
because I was using the ANONYMOUS LOGON I had to give that exec rights on that newly created SP. After that everything worked like it should. &lt;/p&gt;

&lt;p&gt;A little bird also told me that the windows authentication didn&#039;t work because of to many jumps. Next time I&#039;ll try to solve that if possible. &lt;/p&gt;

&lt;p&gt;I would like to thank George and Ted for their patience and help in solving this problem.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/sql-server-linked-server-between-2005-64&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>Today I wanted to import the last bits of data from the old server. The new server is a 2005 64 bits SQL server and the old server is a 2000 32 bits. I'm no DBA and everything is internal so I don't really care about service packs and I can't remember which has which allthough I'm sure the 2000 box has the latest SP but since they aren't even connected to the internet updating isn't easy. </p>

<p>So today I setup a linked server between the two. I used my desktop to connect to the new server and then setup the linked server. And surprise surprise it didn't work. This was more or less the error I got. </p>

<blockquote><p><strong>OLE DB provider "SQLNCLI" for linked server "servername" returned message "Communication link failure".<br />
Msg 10054, Level 16, State 1, Line 0<br />
TCP Provider: An existing connection was forcibly closed by the remote host.<br />
Msg 18456, Level 14, State 1, Line 0<br />
Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.</strong></p></blockquote>

<p>I actually never solved this problem. I just gave ANONYMOUS LOGON rights on the database and deleted it shortly after. It is internal remember. That solved that error message. On to the next error message.</p>

<blockquote><p><strong>OLE DB provider "SQLNCLI" for linked server "servername" returned message "Unspecified error".<br />
OLE DB provider "SQLNCLI" for linked server "servername" returned message "The stored procedure required to complete this operation could not be found on the server. Please contact your system administrator.".<br />
Msg 7311, Level 16, State 2, Line 1<br />
Cannot obtain the schema rowset "DBSCHEMA_TABLES_INFO" for OLE DB provider "SQLNCLI" for linked server "servername". The provider supports the interface, but returns a failure code when it is used.</strong></p></blockquote>

<p>This one was solved by doing a google. And finding <a href="http://blog.sqlauthority.com/2007/05/04/sql-server-fix-error-msg-7311-level-16-state-2-line-1-cannot-obtain-the-schema-rowset-dbschema_tables_info-for-ole-db-provider-sqlncli-for-linked-server-linkedservername/">this</a>.</p>

<p>At the same time Ted (onpnt) gave me <a href="http://blog.raffaeu.com/archive/2008/06/19/sql-2005-and-linked-server-cannot-obtain-the-schema-rowset.aspx">this solution</a> and he the asked why I hadn't told him it was a 64 bit 2005 and the 2000 was 32 bit. Well Ted you didn't ask ;-). So it's all Teds fault it took me more then an hour to figure this out. Well that's my story anyway. </p>

<p>The solution is to create this procedure.</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb95396'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb95396','cb56858'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb95396" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">create</span> <span style="color: #0000FF;">procedure</span> <span style="color: #AF0000;">sp_tables_info_rowset_64</span></li><li style="" class="li2">@table_name <span style="color: #0000FF;">sysname</span>,</li><li style="" class="li1">@table_schema <span style="color: #0000FF;">sysname</span> = null,</li><li style="" class="li2">@table_type <span style="color: #0000FF;">nvarchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span> = null</li><li style="" class="li1"><span style="color: #0000FF;">as</span></li><li style="" class="li2"><span style="color: #0000FF;">declare</span> @<span style="color: #0000FF;">Result</span> <span style="color: #0000FF;">int</span> <span style="color: #0000FF;">set</span> @<span style="color: #0000FF;">Result</span> = <span style="color: #000;">0</span></li><li style="" class="li1">&nbsp; <span style="color: #0000FF;">exec</span> @<span style="color: #0000FF;">Result</span> = <span style="color: #AF0000;">sp_tables_info_rowset</span> @table_name, @table_schema, @table_type</li></ol></div><div id="cb56858" style="display: none; color: red;"></div></div></div>
<p>  <br />
because I was using the ANONYMOUS LOGON I had to give that exec rights on that newly created SP. After that everything worked like it should. </p>

<p>A little bird also told me that the windows authentication didn't work because of to many jumps. Next time I'll try to solve that if possible. </p>

<p>I would like to thank George and Ted for their patience and help in solving this problem.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/sql-server-linked-server-between-2005-64">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/sql-server-linked-server-between-2005-64#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=288</wfw:commentRss>
		</item>
				<item>
			<title>Altering the Schema of a stored procedure in SQL-server 2005</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/MSSQLServer/altering-the-schema-of-a-stored-procedur-2005</link>
			<pubDate>Tue, 06 Jan 2009 06:35:29 +0000</pubDate>			<dc:creator>Christiaan Baes (chrissie1)</dc:creator>
			<category domain="main">Microsoft SQL Server</category>			<guid isPermaLink="false">282@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;Today I had to change the schema of a stored procedure. I couldn&#039;t find a clicky click method to do this in SQL server management studio (which kinda worries me). So I looked on google for a method and found &lt;a href=&quot;http://weblogs.asp.net/steveschofield/archive/2005/12/31/change-schema-name-on-tables-and-stored-procedures-in-sql-server-2005.aspx&quot;&gt;this&lt;/a&gt;. But not being an SQLguru I took a few seconds to sink in.&lt;/p&gt;

&lt;p&gt;So the syntax is.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;&lt;span class=&quot;MT_blue&quot;&gt;ALTER SCHEMA&lt;/span&gt; nameoftheschematotransferto &lt;span class=&quot;MT_blue&quot;&gt;TRANSFER&lt;/span&gt; nameandschemaoftheSP&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;We have an SP called username.spo1 and I want to change it to dbo.spo1 so I would change it from schema username to schema dbo. This would then mean &lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb34381&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;ALTER&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;SCHEMA&lt;/span&gt; dbo &lt;span style=&quot;color: #0000FF;&quot;&gt;TRANSFER&lt;/span&gt; username.&lt;span style=&quot;color: #202020;&quot;&gt;spo1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb85508&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The funny thing is that not even SQL prompt from Redgate recognizes the word TRANSFER as a keyword. So I guess transfering schemas is not a very common event.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/MSSQLServer/altering-the-schema-of-a-stored-procedur-2005&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>Today I had to change the schema of a stored procedure. I couldn't find a clicky click method to do this in SQL server management studio (which kinda worries me). So I looked on google for a method and found <a href="http://weblogs.asp.net/steveschofield/archive/2005/12/31/change-schema-name-on-tables-and-stored-procedures-in-sql-server-2005.aspx">this</a>. But not being an SQLguru I took a few seconds to sink in.</p>

<p>So the syntax is.</p>

<blockquote><p><span class="MT_blue">ALTER SCHEMA</span> nameoftheschematotransferto <span class="MT_blue">TRANSFER</span> nameandschemaoftheSP</p></blockquote>

<p>For example:</p>

<p>We have an SP called username.spo1 and I want to change it to dbo.spo1 so I would change it from schema username to schema dbo. This would then mean </p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb64792'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb64792','cb4859'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb64792" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">SCHEMA</span> dbo <span style="color: #0000FF;">TRANSFER</span> username.<span style="color: #202020;">spo1</span></li></ol></div><div id="cb4859" style="display: none; color: red;"></div></div></div>

<p>The funny thing is that not even SQL prompt from Redgate recognizes the word TRANSFER as a keyword. So I guess transfering schemas is not a very common event.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/MSSQLServer/altering-the-schema-of-a-stored-procedur-2005">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/MSSQLServer/altering-the-schema-of-a-stored-procedur-2005#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=282</wfw:commentRss>
		</item>
				<item>
			<title>SQL Dependency tracker and pretty pictures</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/sql-dependency-tracker-and-pretty-pictur</link>
			<pubDate>Tue, 10 Jun 2008 11:14:56 +0000</pubDate>			<dc:creator>Christiaan Baes (chrissie1)</dc:creator>
			<category domain="main">Data Modelling &amp; Design</category>			<guid isPermaLink="false">45@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;Today I finally got &lt;a href=&quot;http://www.red-gate.com/products/SQL_Professional_Toolbelt/index.htm&quot;&gt;SQL-Toolbelt&lt;/a&gt; from &lt;a href=&quot;http://www.red-gate.com/&quot;&gt;RedGate Software&lt;/a&gt; and I just had to play with it a bit. &lt;/p&gt;

&lt;p&gt;I especcially liked the dependency tracker and the pretty picture it produced from my Database. Look.&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;img src=&quot;http://blogs.lessthandot.com/media/blogs/DataMgmt/SQLToolbetdependecytracker.JPG&quot; alt=&quot;&quot; title=&quot;&quot; width=&quot;748&quot; height=&quot;625&quot; /&gt;&lt;/div&gt;&lt;p&gt; &lt;/p&gt;

&lt;p&gt;Isn&amp;#8217;t it pretty? It&amp;#8217;s art &lt;img src=&quot;http://blogs.lessthandot.com/rsc/smilies/icon_razz.gif&quot; title=&quot;:p&quot; alt=&quot;:p&quot; class=&quot;middle&quot; width=&quot;15&quot; height=&quot;15&quot; /&gt;.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/sql-dependency-tracker-and-pretty-pictur&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>Today I finally got <a href="http://www.red-gate.com/products/SQL_Professional_Toolbelt/index.htm">SQL-Toolbelt</a> from <a href="http://www.red-gate.com/">RedGate Software</a> and I just had to play with it a bit. </p>

<p>I especcially liked the dependency tracker and the pretty picture it produced from my Database. Look.</p>

<div class="image_block"><img src="http://blogs.lessthandot.com/media/blogs/DataMgmt/SQLToolbetdependecytracker.JPG" alt="" title="" width="748" height="625" /></div><p> </p>

<p>Isn&#8217;t it pretty? It&#8217;s art <img src="http://blogs.lessthandot.com/rsc/smilies/icon_razz.gif" title=":p" alt=":p" class="middle" width="15" height="15" />.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/sql-dependency-tracker-and-pretty-pictur">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/sql-dependency-tracker-and-pretty-pictur#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=45</wfw:commentRss>
		</item>
			</channel>
</rss>
