<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Philip Hendry&#039;s Blog</title>
	<atom:link href="http://philiphendry.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://philiphendry.wordpress.com</link>
	<description>One day there&#039;ll be enough time...</description>
	<lastBuildDate>Tue, 29 Sep 2009 11:51:04 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='philiphendry.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/d8bbdd827d06a261a6946a585d8d77d4?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Philip Hendry&#039;s Blog</title>
		<link>http://philiphendry.wordpress.com</link>
	</image>
			<item>
		<title>Setting Opera as the default browser on a Windows Mobile</title>
		<link>http://philiphendry.wordpress.com/2009/09/29/setting-opera-as-the-default-browser-on-a-windows-mobile/</link>
		<comments>http://philiphendry.wordpress.com/2009/09/29/setting-opera-as-the-default-browser-on-a-windows-mobile/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 11:47:46 +0000</pubDate>
		<dc:creator>philiphendry</dc:creator>
				<category><![CDATA[Windows Mobile]]></category>

		<guid isPermaLink="false">http://philiphendry.wordpress.com/2009/09/29/setting-opera-as-the-default-browser-on-a-windows-mobile/</guid>
		<description><![CDATA[I own an HTC Touch HD as was getting a bit annoyed at Internet Explorer being the default browser when selecting links from emails. However, Opera Mobile has a ‘hidden’ configuration screen and can be used to set it as the default :

Run Opera
Enter ‘opera:config’ in the address bar
Find the ‘Install’ section
Select ‘Browser First Time [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=philiphendry.wordpress.com&blog=3012011&post=294&subd=philiphendry&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I own an HTC Touch HD as was getting a bit annoyed at Internet Explorer being the default browser when selecting links from emails. However, Opera Mobile has a ‘hidden’ configuration screen and can be used to set it as the default :</p>
<ol>
<li>Run Opera</li>
<li>Enter ‘opera:config’ in the address bar</li>
<li>Find the ‘Install’ section</li>
<li>Select ‘Browser First Time Launch’ checkbox</li>
<li>Press ‘Save’</li>
<li>Soft reset</li>
</ol>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/philiphendry.wordpress.com/294/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/philiphendry.wordpress.com/294/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/philiphendry.wordpress.com/294/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/philiphendry.wordpress.com/294/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/philiphendry.wordpress.com/294/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/philiphendry.wordpress.com/294/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/philiphendry.wordpress.com/294/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/philiphendry.wordpress.com/294/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/philiphendry.wordpress.com/294/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/philiphendry.wordpress.com/294/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=philiphendry.wordpress.com&blog=3012011&post=294&subd=philiphendry&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://philiphendry.wordpress.com/2009/09/29/setting-opera-as-the-default-browser-on-a-windows-mobile/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/21cb73fde009d63fbcca11c16adebdfc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Phil</media:title>
		</media:content>
	</item>
		<item>
		<title>Generating a list of numbers in T-SQL</title>
		<link>http://philiphendry.wordpress.com/2009/09/29/generating-a-list-of-numbers-in-t-sql/</link>
		<comments>http://philiphendry.wordpress.com/2009/09/29/generating-a-list-of-numbers-in-t-sql/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 08:33:06 +0000</pubDate>
		<dc:creator>philiphendry</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://philiphendry.wordpress.com/2009/09/29/generating-a-list-of-numbers-in-t-sql/</guid>
		<description><![CDATA[I wanted to create a list of numbers so I could cross join them to another set of data to generate some test data quickly. There are ways to generate numbers using a CTE (Common Table Expression) or if you’re in a real hurry you can make us of a fairly undocumented table called master..spt_values. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=philiphendry.wordpress.com&blog=3012011&post=293&subd=philiphendry&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I wanted to create a list of numbers so I could cross join them to another set of data to generate some test data quickly. There are ways to generate numbers using a CTE (Common Table Expression) or if you’re in a real hurry you can make us of a fairly undocumented table called master..spt_values. Seeing as this table isn’t well documented don’t go using it for production code since it might change but for quick one-off tasks it seems fine.</p>
<p>The following SQL creates a list of numbers from 0 to 2047 :</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:a90f5c3c-4992-4d92-84c1-a71fe582fffb" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;white-space:pre-wrap;overflow:auto;"><span style="color:#0000FF;">select</span><span style="color:#000000;"> </span><span style="color:#FF0000;">[</span><span style="color:#FF0000;">number</span><span style="color:#FF0000;">]</span><span style="color:#000000;">
</span><span style="color:#0000FF;">from</span><span style="color:#000000;"> master..spt_values
</span><span style="color:#0000FF;">where</span><span style="color:#000000;"> type </span><span style="color:#808080;">=</span><span style="color:#000000;"> </span><span style="color:#FF0000;">'</span><span style="color:#FF0000;">P</span><span style="color:#FF0000;">'</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/philiphendry.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/philiphendry.wordpress.com/293/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/philiphendry.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/philiphendry.wordpress.com/293/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/philiphendry.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/philiphendry.wordpress.com/293/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/philiphendry.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/philiphendry.wordpress.com/293/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/philiphendry.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/philiphendry.wordpress.com/293/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=philiphendry.wordpress.com&blog=3012011&post=293&subd=philiphendry&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://philiphendry.wordpress.com/2009/09/29/generating-a-list-of-numbers-in-t-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/21cb73fde009d63fbcca11c16adebdfc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Phil</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.NET Page Life Cycle Diagram</title>
		<link>http://philiphendry.wordpress.com/2009/09/21/asp-net-page-life-cycle-diagram/</link>
		<comments>http://philiphendry.wordpress.com/2009/09/21/asp-net-page-life-cycle-diagram/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 19:42:56 +0000</pubDate>
		<dc:creator>philiphendry</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://philiphendry.wordpress.com/2009/09/21/asp-net-page-life-cycle-diagram/</guid>
		<description><![CDATA[I saw this months ago and wondered where it had gone so when I came across it by chance whilst googling I thought I would save myself a link to it. Many thanks to Raymond Lewallen who credits Leon Andrianarivony!

       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=philiphendry.wordpress.com&blog=3012011&post=292&subd=philiphendry&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I saw this months ago and wondered where it had gone so when I came across it by chance whilst googling I thought I would save myself a link to it. Many thanks to <a href="http://codebetter.com/blogs/raymond.lewallen/archive/2005/03/10/59583.aspx">Raymond Lewallen</a> who credits Leon Andrianarivony!</p>
<p><a href="http://philiphendry.files.wordpress.com/2009/09/image.png"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="image" border="0" alt="image" src="http://philiphendry.files.wordpress.com/2009/09/image_thumb.png?w=881&#038;h=1204" width="881" height="1204" /></a></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/philiphendry.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/philiphendry.wordpress.com/292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/philiphendry.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/philiphendry.wordpress.com/292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/philiphendry.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/philiphendry.wordpress.com/292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/philiphendry.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/philiphendry.wordpress.com/292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/philiphendry.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/philiphendry.wordpress.com/292/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=philiphendry.wordpress.com&blog=3012011&post=292&subd=philiphendry&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://philiphendry.wordpress.com/2009/09/21/asp-net-page-life-cycle-diagram/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/21cb73fde009d63fbcca11c16adebdfc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Phil</media:title>
		</media:content>

		<media:content url="http://philiphendry.files.wordpress.com/2009/09/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Sproc Compile Locks</title>
		<link>http://philiphendry.wordpress.com/2009/09/21/sproc-compile-locks/</link>
		<comments>http://philiphendry.wordpress.com/2009/09/21/sproc-compile-locks/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 19:28:48 +0000</pubDate>
		<dc:creator>philiphendry</dc:creator>
				<category><![CDATA[MSDN Article Summary]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://philiphendry.wordpress.com/2009/09/21/sproc-compile-locks/</guid>
		<description><![CDATA[I came across an article on Microsofts support site which has raised a point which I’d never considered before. It basically says that if the user that executes a stored procedure is not the owner of the procedure then locks are acquired during the process to find a cached plan that may lead to blocking. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=philiphendry.wordpress.com&blog=3012011&post=289&subd=philiphendry&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I came across an <a href="http://support.microsoft.com/?id=263889">article</a> on Microsofts support site which has raised a point which I’d never considered before. It basically says that if the user that executes a stored procedure is not the owner of the procedure then locks are acquired during the process to find a cached plan that may lead to blocking. It also states this could be avoided by fully qualifying the sproc name (e.g. dbo.mysproc) when calling it to avoid the extra lookups. This has been a problem for me in the past since the projects I’ve worked on had been setup with an account running as dbowner, however, if I was setting up a database from scratch I’d set up a specific user(s) for accessing the database and give it just the permissions it requires (sproc execute permissions for example.) I think, therefore, this would fall into these problem. However, I would also make use of the schema prefix (e.g. Sales.Order table) rather than leaving it as dbo and therefore avoid this problem altogether.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/philiphendry.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/philiphendry.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/philiphendry.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/philiphendry.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/philiphendry.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/philiphendry.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/philiphendry.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/philiphendry.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/philiphendry.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/philiphendry.wordpress.com/289/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=philiphendry.wordpress.com&blog=3012011&post=289&subd=philiphendry&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://philiphendry.wordpress.com/2009/09/21/sproc-compile-locks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/21cb73fde009d63fbcca11c16adebdfc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Phil</media:title>
		</media:content>
	</item>
		<item>
		<title>Generic Sorting Routine for ASP.NET GridView</title>
		<link>http://philiphendry.wordpress.com/2009/09/18/generic-sorting-routine-for-asp-net-gridview/</link>
		<comments>http://philiphendry.wordpress.com/2009/09/18/generic-sorting-routine-for-asp-net-gridview/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 19:41:28 +0000</pubDate>
		<dc:creator>philiphendry</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Dev Problem]]></category>
		<category><![CDATA[LINQ]]></category>

		<guid isPermaLink="false">http://philiphendry.wordpress.com/2009/09/18/generic-sorting-routine-for-asp-net-gridview/</guid>
		<description><![CDATA[I noticed a lot of code in the current project I’m working on which looked something like this :

switch (sortExpression)
{
    case "Name":
        items.OrderBy(i =&#62; i.Name);
        break;
    case "Date":
        [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=philiphendry.wordpress.com&blog=3012011&post=288&subd=philiphendry&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I noticed a lot of code in the current project I’m working on which looked something like this :</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:9dcbbfa2-a320-41d2-b99b-e0af15870017" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;white-space:pre-wrap;overflow:auto;"><span style="color:#0000FF;">switch</span><span style="color:#000000;"> (sortExpression)
{
    </span><span style="color:#0000FF;">case</span><span style="color:#000000;"> </span><span style="color:#800000;">"</span><span style="color:#800000;">Name</span><span style="color:#800000;">"</span><span style="color:#000000;">:
        items.OrderBy(i </span><span style="color:#000000;">=&gt;</span><span style="color:#000000;"> i.Name);
        </span><span style="color:#0000FF;">break</span><span style="color:#000000;">;
    </span><span style="color:#0000FF;">case</span><span style="color:#000000;"> </span><span style="color:#800000;">"</span><span style="color:#800000;">Date</span><span style="color:#800000;">"</span><span style="color:#000000;">:
        items.OrderBy(i </span><span style="color:#000000;">=&gt;</span><span style="color:#000000;"> i.Date);
        </span><span style="color:#0000FF;">break</span><span style="color:#000000;">;
    </span><span style="color:#0000FF;">case</span><span style="color:#000000;"> </span><span style="color:#800000;">"</span><span style="color:#800000;">Cost</span><span style="color:#800000;">"</span><span style="color:#000000;">:
        items.OrderBy(i </span><span style="color:#000000;">=&gt;</span><span style="color:#000000;"> i.Cost);
        </span><span style="color:#0000FF;">break</span><span style="color:#000000;">;
}</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>This was then repeated all over again for descending orders!! I’ve now replaced it with something like this :</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:94a8b1a3-d9bd-4fb9-a698-fe38c4150b36" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;white-space:pre-wrap;overflow:auto;"><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> Populate(</span><span style="color:#0000FF;">string</span><span style="color:#000000;"> sortExpression)
{
   var items </span><span style="color:#000000;">=</span><span style="color:#000000;"> GetData();
   gvList.DataSource </span><span style="color:#000000;">=</span><span style="color:#000000;"> CreateValueList(items).OrderByExpression(</span><span style="color:#0000FF;">new</span><span style="color:#000000;"> OrderByExpression(sortExpression));
   gvList.DataBind();
}</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>The sort expression is handled by the GridView code such that AllowSorting is turned on and the OnSorting event is wired up to a method :</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:d905377e-4f3d-48a6-8e24-ed92156c9b6b" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;white-space:pre-wrap;overflow:auto;"><span style="color:#000000;">&lt;</span><span style="color:#000000;">asp:GridView ID</span><span style="color:#000000;">=</span><span style="color:#800000;">"</span><span style="color:#800000;">gvList</span><span style="color:#800000;">"</span><span style="color:#000000;"> runat</span><span style="color:#000000;">=</span><span style="color:#800000;">"</span><span style="color:#800000;">server</span><span style="color:#800000;">"</span><span style="color:#000000;"> AllowSorting</span><span style="color:#000000;">=</span><span style="color:#800000;">"</span><span style="color:#800000;">True</span><span style="color:#800000;">"</span><span style="color:#000000;"> OnSorting</span><span style="color:#000000;">=</span><span style="color:#800000;">"</span><span style="color:#800000;">gvList_Sorting</span><span style="color:#800000;">"</span><span style="color:#000000;"> DataKeyNames</span><span style="color:#000000;">=</span><span style="color:#800000;">"</span><span style="color:#800000;">ID</span><span style="color:#800000;">"</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">
   </span><span style="color:#000000;">&lt;</span><span style="color:#000000;">Columns</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">
       </span><span style="color:#000000;">&lt;</span><span style="color:#000000;">asp:TemplateField HeaderText</span><span style="color:#000000;">=</span><span style="color:#800000;">"</span><span style="color:#800000;">Name</span><span style="color:#800000;">"</span><span style="color:#000000;"> SortExpression</span><span style="color:#000000;">=</span><span style="color:#800000;">"</span><span style="color:#800000;">Name</span><span style="color:#800000;">"</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">
           </span><span style="color:#000000;">&lt;</span><span style="color:#000000;">ItemTemplate</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">
               </span><span style="color:#000000;">&lt;</span><span style="color:#000000;">asp:Label Text</span><span style="color:#000000;">=</span><span style="color:#800000;">'</span><span style="color:#800000;">&lt;%# DataBinder.Eval(Container.DataItem, "Name") %&gt;</span><span style="color:#800000;">'</span><span style="color:#000000;"> runat</span><span style="color:#000000;">=</span><span style="color:#800000;">"</span><span style="color:#800000;">server</span><span style="color:#800000;">"</span><span style="color:#000000;"> ID</span><span style="color:#000000;">=</span><span style="color:#800000;">"</span><span style="color:#800000;">lblName</span><span style="color:#800000;">"</span><span style="color:#000000;"> </span><span style="color:#000000;">/&gt;</span><span style="color:#000000;">
           </span><span style="color:#000000;">&lt;/</span><span style="color:#000000;">ItemTemplate</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">
       </span><span style="color:#000000;">&lt;/</span><span style="color:#000000;">asp:TemplateField</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">
   </span><span style="color:#000000;">&lt;/</span><span style="color:#000000;">Columns</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">
</span><span style="color:#000000;">&lt;/</span><span style="color:#000000;">asp:GridView</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">
</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>The code-behind deals with the sorting events and calls populate :</p>
<p><div style="display:inline;float:none;margin:0;padding:0;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:60e64ffe-1de8-4e0e-9536-18ae0c51ca4a" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;white-space:pre-wrap;overflow:auto;"><span style="color:#0000FF;">protected</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> gvList_Sorting(</span><span style="color:#0000FF;">object</span><span style="color:#000000;"> sender, GridViewSortEventArgs e)
{
   Populate(e.SortExpression </span><span style="color:#000000;">+</span><span style="color:#000000;"> </span><span style="color:#800000;">"</span><span style="color:#800000;"> </span><span style="color:#800000;">"</span><span style="color:#000000;"> </span><span style="color:#000000;">+</span><span style="color:#000000;"> GetSortDirection(e.SortExpression));
}

</span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">string</span><span style="color:#000000;"> GetSortDirection(</span><span style="color:#0000FF;">string</span><span style="color:#000000;"> column)
{

   </span><span style="color:#008000;">//</span><span style="color:#008000;"> By default, set the sort direction to ascending.</span><span style="color:#008000;">
</span><span style="color:#000000;">   </span><span style="color:#0000FF;">string</span><span style="color:#000000;"> sortDirection </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800000;">"</span><span style="color:#800000;">ASC</span><span style="color:#800000;">"</span><span style="color:#000000;">;

   </span><span style="color:#008000;">//</span><span style="color:#008000;"> Retrieve the last column that was sorted.</span><span style="color:#008000;">
</span><span style="color:#000000;">   </span><span style="color:#0000FF;">string</span><span style="color:#000000;"> sortExpression </span><span style="color:#000000;">=</span><span style="color:#000000;"> ViewState[</span><span style="color:#800000;">"</span><span style="color:#800000;">SortExpression</span><span style="color:#800000;">"</span><span style="color:#000000;">] </span><span style="color:#0000FF;">as</span><span style="color:#000000;"> </span><span style="color:#0000FF;">string</span><span style="color:#000000;">;

   </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (sortExpression </span><span style="color:#000000;">!=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">)
   {
       </span><span style="color:#008000;">//</span><span style="color:#008000;"> Check if the same column is being sorted.
       </span><span style="color:#008000;">//</span><span style="color:#008000;"> Otherwise, the default value can be returned.</span><span style="color:#008000;">
</span><span style="color:#000000;">       </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (sortExpression </span><span style="color:#000000;">==</span><span style="color:#000000;"> column)
       {
           </span><span style="color:#0000FF;">string</span><span style="color:#000000;"> lastDirection </span><span style="color:#000000;">=</span><span style="color:#000000;"> ViewState[</span><span style="color:#800000;">"</span><span style="color:#800000;">SortDirection</span><span style="color:#800000;">"</span><span style="color:#000000;">] </span><span style="color:#0000FF;">as</span><span style="color:#000000;"> </span><span style="color:#0000FF;">string</span><span style="color:#000000;">;
           </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> ((lastDirection </span><span style="color:#000000;">!=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">) </span><span style="color:#000000;">&amp;&amp;</span><span style="color:#000000;"> (lastDirection </span><span style="color:#000000;">==</span><span style="color:#000000;"> </span><span style="color:#800000;">"</span><span style="color:#800000;">ASC</span><span style="color:#800000;">"</span><span style="color:#000000;">))
           {
               sortDirection </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800000;">"</span><span style="color:#800000;">DESC</span><span style="color:#800000;">"</span><span style="color:#000000;">;
           }
       }
   }

   </span><span style="color:#008000;">//</span><span style="color:#008000;"> Save new values in ViewState.</span><span style="color:#008000;">
</span><span style="color:#000000;">   ViewState[</span><span style="color:#800000;">"</span><span style="color:#800000;">SortDirection</span><span style="color:#800000;">"</span><span style="color:#000000;">] </span><span style="color:#000000;">=</span><span style="color:#000000;"> sortDirection;
   ViewState[</span><span style="color:#800000;">"</span><span style="color:#800000;">SortExpression</span><span style="color:#800000;">"</span><span style="color:#000000;">] </span><span style="color:#000000;">=</span><span style="color:#000000;"> column;

   </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> sortDirection;
}
</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</p>
<p>What this all boils down to is the <em>OrderByExpression()</em> extension method called in the <em>Populate()</em> method above:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:cb88776a-97c8-4349-bf59-2c092779690f" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;overflow:auto;"><span style="color:#000000;">   </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">static</span><span style="color:#000000;"> IEnumerable</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">TSource</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> OrderByExpression</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">TSource</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">(</span><span style="color:#0000FF;">this</span><span style="color:#000000;"> IEnumerable</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">TSource</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> data, OrderByExpression expression)
   {
       </span><span style="color:#0000FF;">string</span><span style="color:#000000;"> sortOrderMethod </span><span style="color:#000000;">=</span><span style="color:#000000;"> (expression.SortOrder </span><span style="color:#000000;">==</span><span style="color:#000000;"> SortOrderEnum.Ascending) </span><span style="color:#000000;">?</span><span style="color:#000000;"> </span><span style="color:#800000;">"</span><span style="color:#800000;">OrderBy</span><span style="color:#800000;">"</span><span style="color:#000000;"> : </span><span style="color:#800000;">"</span><span style="color:#800000;">OrderByDescending</span><span style="color:#800000;">"</span><span style="color:#000000;">;

       </span><span style="color:#008000;">//</span><span style="color:#008000;"> data.OrderBy(o =&gt; o.propertyname);   </span><span style="color:#008000;">
</span><span style="color:#000000;">       var dataAsQueryable </span><span style="color:#000000;">=</span><span style="color:#000000;"> data.AsQueryable</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">TSource</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">();
       ParameterExpression lambdaParameter </span><span style="color:#000000;">=</span><span style="color:#000000;"> Expression.Parameter(</span><span style="color:#0000FF;">typeof</span><span style="color:#000000;">(TSource), </span><span style="color:#800000;">"</span><span style="color:#800000;">o</span><span style="color:#800000;">"</span><span style="color:#000000;">);
       MemberExpression member </span><span style="color:#000000;">=</span><span style="color:#000000;"> Expression.PropertyOrField(lambdaParameter, expression.SortProperties[</span><span style="color:#800080;">0</span><span style="color:#000000;">]);
       LambdaExpression lambda </span><span style="color:#000000;">=</span><span style="color:#000000;"> Expression.Lambda(member, lambdaParameter);
       Type[] argumentTypes </span><span style="color:#000000;">=</span><span style="color:#000000;"> { dataAsQueryable.ElementType, lambda.Body.Type };
       MethodCallExpression orderBy </span><span style="color:#000000;">=</span><span style="color:#000000;"> Expression.Call(</span><span style="color:#0000FF;">typeof</span><span style="color:#000000;">(Queryable), sortOrderMethod, argumentTypes, dataAsQueryable.Expression, lambda);
       </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> dataAsQueryable.Provider.CreateQuery</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">TSource</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">(orderBy);
   }</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>I have to say thanks to Joseph Albahari and Ben Albahari of <a href="www.linqpad.net">LinqPad</a> fame since I found this solution to my problems (after getting within so close through my own efforts whilst our internet connection was down in the office!!) in the samples that came with LinqPad.</p>
<p>The code above creates a dynamic Linq expression then executes it through the queryables provider – although this only occurs once the whole linq expression is enumerated.</p>
<p>The last few modifications I need to make require the order by to cope with multiple properties (The <em>OrderByExpression.SortProperties</em> class already supports multiple properties but I’m only taking the first at the moment) and I need to ensure that the query always deferred since composable against a database – this is important since I’ve yet to consider paging in the GridView and I want to make sure that specifiying <em>.Skip(n).Take(m)</em> can be applied after the ordering but the Linq expression be composed as SQL and executed against the database in one go otherwise I’ll be returning all the rows to the application layer before extracting just the required rows for the current page.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/philiphendry.wordpress.com/288/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/philiphendry.wordpress.com/288/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/philiphendry.wordpress.com/288/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/philiphendry.wordpress.com/288/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/philiphendry.wordpress.com/288/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/philiphendry.wordpress.com/288/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/philiphendry.wordpress.com/288/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/philiphendry.wordpress.com/288/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/philiphendry.wordpress.com/288/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/philiphendry.wordpress.com/288/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=philiphendry.wordpress.com&blog=3012011&post=288&subd=philiphendry&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://philiphendry.wordpress.com/2009/09/18/generic-sorting-routine-for-asp-net-gridview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/21cb73fde009d63fbcca11c16adebdfc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Phil</media:title>
		</media:content>
	</item>
		<item>
		<title>Importing from Excel into SQL Server</title>
		<link>http://philiphendry.wordpress.com/2009/09/15/importing-from-excel-into-sql-server/</link>
		<comments>http://philiphendry.wordpress.com/2009/09/15/importing-from-excel-into-sql-server/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 10:54:41 +0000</pubDate>
		<dc:creator>philiphendry</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://philiphendry.wordpress.com/2009/09/15/importing-from-excel-into-sql-server/</guid>
		<description><![CDATA[I was going through a mountain of pain trying to get an import working from an Excel spreadsheet working into SQL Server 2005 but I finally managed it and here’s how…
Here’s the SQL I’m using (slightly abridged!) :


set transaction isolation level read committed

declare @sql nvarchar(1024)
set @sql = 'select * into ##Temp from opendatasource(''Microsoft.Jet.OLEDB.4.0'', ''Extended Properties=Excel [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=philiphendry.wordpress.com&blog=3012011&post=287&subd=philiphendry&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I was going through a mountain of pain trying to get an import working from an Excel spreadsheet working into SQL Server 2005 but I finally managed it and here’s how…</p>
<p>Here’s the SQL I’m using (slightly abridged!) :</p>
<p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:6d9821e0-baa1-43f2-8f3b-0cda38d25d49" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;white-space:pre-wrap;overflow:auto;"><span style="color:#0000FF;">set</span><span style="color:#000000;"> </span><span style="color:#0000FF;">transaction</span><span style="color:#000000;"> </span><span style="color:#0000FF;">isolation</span><span style="color:#000000;"> </span><span style="color:#0000FF;">level</span><span style="color:#000000;"> </span><span style="color:#0000FF;">read</span><span style="color:#000000;"> </span><span style="color:#0000FF;">committed</span><span style="color:#000000;">

</span><span style="color:#0000FF;">declare</span><span style="color:#000000;"> </span><span style="color:#008000;">@sql</span><span style="color:#000000;"> </span><span style="color:#0000FF;">nvarchar</span><span style="color:#000000;">(</span><span style="color:#800000;font-weight:bold;">1024</span><span style="color:#000000;">)
</span><span style="color:#0000FF;">set</span><span style="color:#000000;"> </span><span style="color:#008000;">@sql</span><span style="color:#000000;"> </span><span style="color:#808080;">=</span><span style="color:#000000;"> </span><span style="color:#FF0000;">'</span><span style="color:#FF0000;">select * into ##Temp from opendatasource(</span><span style="color:#FF0000;">''</span><span style="color:#FF0000;">Microsoft.Jet.OLEDB.4.0</span><span style="color:#FF0000;">''</span><span style="color:#FF0000;">, </span><span style="color:#FF0000;">''</span><span style="color:#FF0000;">Extended Properties=Excel 8.0;Data Source=</span><span style="color:#FF0000;">'</span><span style="color:#000000;"> </span><span style="color:#808080;">+</span><span style="color:#000000;"> </span><span style="color:#008000;">@ExcelFileToImport</span><span style="color:#000000;"> </span><span style="color:#808080;">+</span><span style="color:#000000;"> </span><span style="color:#FF0000;">'''</span><span style="color:#FF0000;">)...</span><span style="color:#FF0000;">'</span><span style="color:#000000;"> </span><span style="color:#808080;">+</span><span style="color:#000000;"> </span><span style="color:#008000;">@ExcelWorkSheet</span><span style="color:#000000;">
</span><span style="color:#0000FF;">exec</span><span style="color:#000000;"> sp_executesql </span><span style="color:#008000;">@sql</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</p>
<p>Points to note :</p>
<ul>
<li>I’m using dynamic sql because the opendatasource() doesn’t like being passed variables… so be sure to validate the contents of @ExcelFileToImport and @ExcelWorkSheet.</li>
<li>Because I was forced to use dynamic sql I had to use a global temporary table. I wanted to load the data into a temporary table so that the columns were generated on-the-fly and I could check the correct columns were supplied by examining tempdb.sys.columns. It therefore had to be a global temporary because a standard one would have been thrown away after sp_executesql() had finished! For my situation the global temporary table is ok… but you’ll have to consider your own situation and whether concurrency allows.</li>
<li>I kept getting the error below on the subsequent re-tries of uploading but worked around this by adding ‘set transaction isolation level read committed’ in the sproc.
<p><em>The requested operation could not be performed because OLE DB provider &quot;Microsoft.Jet.OLEDB.4.0&quot; for linked server &quot;(null)&quot; does not support the required transaction interface.</em></li>
</ul>
<p>I was having trouble executing within a transaction but with the changes made above the sql could be called with the following :</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:efbb52e9-bc99-40d2-8acc-465bb9ad518d" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;white-space:pre-wrap;overflow:auto;"><span style="color:#0000FF;">using</span><span style="color:#000000;"> (TransactionScope scope </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> TransactionScope())
{
    UploadExcelIntoDatabase(importTicket, importFilename);
    scope.Complete();
}
</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/philiphendry.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/philiphendry.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/philiphendry.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/philiphendry.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/philiphendry.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/philiphendry.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/philiphendry.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/philiphendry.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/philiphendry.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/philiphendry.wordpress.com/287/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=philiphendry.wordpress.com&blog=3012011&post=287&subd=philiphendry&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://philiphendry.wordpress.com/2009/09/15/importing-from-excel-into-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/21cb73fde009d63fbcca11c16adebdfc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Phil</media:title>
		</media:content>
	</item>
		<item>
		<title>Conditional Aggregate Totals in SQL</title>
		<link>http://philiphendry.wordpress.com/2009/09/11/conditional-aggregate-totals-in-sql/</link>
		<comments>http://philiphendry.wordpress.com/2009/09/11/conditional-aggregate-totals-in-sql/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 08:03:44 +0000</pubDate>
		<dc:creator>philiphendry</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://philiphendry.wordpress.com/2009/09/11/conditional-aggregate-totals-in-sql/</guid>
		<description><![CDATA[I’ve been working on a SQL Server Reporting Services report which had to display several counts on each row. Each row represented a project and each project could have several tasks that were either ordinary tasks or milestones and could also be escalated. The report need to show something like this :



Project Name
Milestone Counts
Task Count
Escalated [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=philiphendry.wordpress.com&blog=3012011&post=286&subd=philiphendry&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I’ve been working on a SQL Server Reporting Services report which had to display several counts on each row. Each row represented a project and each project could have several tasks that were either ordinary tasks or milestones and could also be escalated. The report need to show something like this :</p>
<table border="1" cellspacing="0" cellpadding="2" width="402">
<tbody>
<tr>
<td valign="top" rowspan="2" width="101">Project Name</td>
<td valign="top" width="118" colspan="5">Milestone Counts</td>
<td valign="top" width="107" colspan="5">Task Count</td>
<td valign="top" rowspan="2" width="74">Escalated Task Count</td>
</tr>
<tr>
<td valign="top" width="123">1st Week</td>
<td valign="top" width="123">2nd Week</td>
<td valign="top" width="123">3rd Week</td>
<td valign="top" width="123">&gt;=4th Week</td>
<td valign="top" width="123">Total</td>
<td valign="top" width="123">1st Week</td>
<td valign="top" width="123">2nd Week</td>
<td valign="top" width="123">3rd Week</td>
<td valign="top" width="123">&gt;=4th Week</td>
<td valign="top" width="123">Total</td>
</tr>
</tbody>
</table>
<p>As you can see a task initially has to break down into two major colours of milestone and ordinary task counts but then is broken down into counts in the 1st, 2nd, 3rd and greater than 4th week totals including the total itself.</p>
<p>Initially this seemed tricky when thinking in terms of using <em>count()</em> but there’s an incredibly simple technique that solves this but which isn’t immediately obvious. The <em>Sum()</em> aggregate function can contain an expression and in this example that expression could compare the task date against late week dates and return either a 1 or 0 :</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:dd56a804-c1db-462f-b75c-5325fd59a393" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;white-space:pre-wrap;overflow:auto;"><span style="color:#0000FF;">select</span><span style="color:#000000;"> ProjectName,
   </span><span style="color:#FF00FF;">sum</span><span style="color:#000000;">(</span><span style="color:#FF00FF;">case</span><span style="color:#000000;"> </span><span style="color:#0000FF;">when</span><span style="color:#000000;"> IsMilestone </span><span style="color:#808080;">=</span><span style="color:#000000;"> </span><span style="color:#800000;font-weight:bold;">1</span><span style="color:#000000;">
      </span><span style="color:#808080;">and</span><span style="color:#000000;"> TaskDate </span><span style="color:#808080;">&lt;</span><span style="color:#000000;"> </span><span style="color:#008000;">@LateDate</span><span style="color:#000000;">
      </span><span style="color:#808080;">and</span><span style="color:#000000;"> Taskdate </span><span style="color:#808080;">&gt;</span><span style="color:#008000;">@OneWeekLateDate</span><span style="color:#000000;">
      </span><span style="color:#0000FF;">then</span><span style="color:#000000;"> </span><span style="color:#800000;font-weight:bold;">1</span><span style="color:#000000;"> </span><span style="color:#0000FF;">else</span><span style="color:#000000;"> </span><span style="color:#800000;font-weight:bold;">0</span><span style="color:#000000;"> </span><span style="color:#0000FF;">end</span><span style="color:#000000;">) </span><span style="color:#0000FF;">as</span><span style="color:#000000;"> Week1LateMilestoneCount
</span><span style="color:#0000FF;">from</span><span style="color:#000000;"> Project
</span><span style="color:#0000FF;">group</span><span style="color:#000000;"> </span><span style="color:#0000FF;">by</span><span style="color:#000000;"> ProjectName</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>I’ve only included one example there but I think it’s enough to get the idea.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/philiphendry.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/philiphendry.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/philiphendry.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/philiphendry.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/philiphendry.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/philiphendry.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/philiphendry.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/philiphendry.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/philiphendry.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/philiphendry.wordpress.com/286/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=philiphendry.wordpress.com&blog=3012011&post=286&subd=philiphendry&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://philiphendry.wordpress.com/2009/09/11/conditional-aggregate-totals-in-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/21cb73fde009d63fbcca11c16adebdfc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Phil</media:title>
		</media:content>
	</item>
		<item>
		<title>Return values from stored procedures using the Enterprise Library Data Access block</title>
		<link>http://philiphendry.wordpress.com/2009/09/07/return-values-from-stored-procedures-using-the-enterprise-library-data-access-block/</link>
		<comments>http://philiphendry.wordpress.com/2009/09/07/return-values-from-stored-procedures-using-the-enterprise-library-data-access-block/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 15:26:13 +0000</pubDate>
		<dc:creator>philiphendry</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Enterprise Library]]></category>

		<guid isPermaLink="false">http://philiphendry.wordpress.com/2009/09/07/return-values-from-stored-procedures-using-the-enterprise-library-data-access-block/</guid>
		<description><![CDATA[I’m not sure why I had so much trouble trying to do this… but because it did I think it’s worth a blog. Basically I was trying to return an int value from a stored procedure but couldn’t quite work out the syntax and was initially distracted by trying to use AddOutParameter() . However, the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=philiphendry.wordpress.com&blog=3012011&post=284&subd=philiphendry&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I’m not sure why I had so much trouble trying to do this… but because it did I think it’s worth a blog. Basically I was trying to return an int value from a stored procedure but couldn’t quite work out the syntax and was initially distracted by trying to use <em>AddOutParameter</em>() . However, the key was to use <em>AddParameter</em>() specifying the direction as <em>ReturnValue</em> :</p>
<p>db.AddParameter(cmd, &quot;@return_value&quot;, DbType.Int32, ParameterDirection.ReturnValue, null, DataRowVersion.Default, null);</p>
<p>Then simply access the named parameter :</p>
<p>Convert.ToInt32(db.GetParameterValue(cmd, &quot;@return_value&quot;))</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/philiphendry.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/philiphendry.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/philiphendry.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/philiphendry.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/philiphendry.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/philiphendry.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/philiphendry.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/philiphendry.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/philiphendry.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/philiphendry.wordpress.com/284/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=philiphendry.wordpress.com&blog=3012011&post=284&subd=philiphendry&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://philiphendry.wordpress.com/2009/09/07/return-values-from-stored-procedures-using-the-enterprise-library-data-access-block/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/21cb73fde009d63fbcca11c16adebdfc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Phil</media:title>
		</media:content>
	</item>
		<item>
		<title>Selecting a result set from a stored procedure in SQL Server</title>
		<link>http://philiphendry.wordpress.com/2009/09/02/selecting-a-result-set-from-a-stored-procedure-in-sql-server/</link>
		<comments>http://philiphendry.wordpress.com/2009/09/02/selecting-a-result-set-from-a-stored-procedure-in-sql-server/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 10:55:10 +0000</pubDate>
		<dc:creator>philiphendry</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://philiphendry.wordpress.com/2009/09/02/selecting-a-result-set-from-a-stored-procedure-in-sql-server/</guid>
		<description><![CDATA[Selecting data from a stored procedure in SQL Server is already a documented feature and here’s an example:
insert into #systables exec sp_executesql N'select * from Northwind.sys.tables'
…problem is this example doesn’t run without first creating the temp table and therefore knowing all the column definitions. When I’m running quick queries this isn’t exactly convenient. I’ve seen [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=philiphendry.wordpress.com&blog=3012011&post=282&subd=philiphendry&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Selecting data from a stored procedure in SQL Server is already a documented feature and here’s an example:</p>
<pre class="code"><span style="color:blue;">insert into </span>#systables <span style="color:blue;">exec </span><span style="color:maroon;">sp_executesql </span>N<span style="color:red;">'select * from Northwind.sys.tables'</span></pre>
<p>…problem is this example doesn’t run without first creating the temp table and therefore knowing all the column definitions. When I’m running quick queries this isn’t exactly convenient. I’ve seen blogs posts using a linked server but there’s another way :</p>
<pre class="code"><span style="color:blue;">select </span><span style="color:gray;">* </span><span style="color:blue;">into </span>#systables
<span style="color:blue;">from openrowset</span><span style="color:gray;">(
   </span><span style="color:red;">'sqlncli'</span><span style="color:gray;">,
   </span><span style="color:red;">'server=.;trusted_connection=Yes'</span><span style="color:gray;">,
   </span><span style="color:red;">'sp_executesql N''select * from Northwind.sys.tables'''
</span><span style="color:gray;">)</span></pre>
<p><a href="http://11011.net/software/vspaste"></a>I wouldn’t necessarily use this as a day-to-day process on a production environment but for administration or scripting installations I think it fits the bill.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/philiphendry.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/philiphendry.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/philiphendry.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/philiphendry.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/philiphendry.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/philiphendry.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/philiphendry.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/philiphendry.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/philiphendry.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/philiphendry.wordpress.com/282/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=philiphendry.wordpress.com&blog=3012011&post=282&subd=philiphendry&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://philiphendry.wordpress.com/2009/09/02/selecting-a-result-set-from-a-stored-procedure-in-sql-server/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/21cb73fde009d63fbcca11c16adebdfc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Phil</media:title>
		</media:content>
	</item>
		<item>
		<title>Lazy Loading Entities Referenced By The Returned Entities from a Stored Procedure in Entity Framework V1</title>
		<link>http://philiphendry.wordpress.com/2009/08/28/lazy-loading-entities-referenced-by-the-returned-entities-from-a-stored-procedure-in-entity-framework-v1/</link>
		<comments>http://philiphendry.wordpress.com/2009/08/28/lazy-loading-entities-referenced-by-the-returned-entities-from-a-stored-procedure-in-entity-framework-v1/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 13:52:39 +0000</pubDate>
		<dc:creator>philiphendry</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Entity Framework]]></category>

		<guid isPermaLink="false">http://philiphendry.wordpress.com/2009/08/28/lazy-loading-entities-referenced-by-the-returned-entities-from-a-stored-procedure-in-entity-framework-v1/</guid>
		<description><![CDATA[Phew, that’s the title out of the way!!
I had a simple plan – run some complex and optimised SQL and return a graph of entities back to the app using Entity Framework. First problem is it doesn’t support returning anything but a single entity from the stored procedure so that’s eager loading done for! Second [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=philiphendry.wordpress.com&blog=3012011&post=276&subd=philiphendry&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Phew, that’s the title out of the way!!</p>
<p>I had a simple plan – run some complex and optimised SQL and return a graph of entities back to the app using Entity Framework. First problem is it doesn’t support returning anything but a single entity from the stored procedure so that’s eager loading done for! Second problem is the entity has to exist in the model so creating a POCO is out of the question and I’m not so sure about creating arbitrary data transfer objects in the model either (EF V2 should help with this.)</p>
<p>So I resorted to running the sproc then lazy loading the child objects I need. What I needed to do though was traverse a couple of references and test a field to limit the returned rows. And here’s what I ended up with after much poking around :</p>
<p><a href="http://philiphendry.files.wordpress.com/2009/08/image8.png"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="image" border="0" alt="image" src="http://philiphendry.files.wordpress.com/2009/08/image_thumb8.png?w=567&#038;h=212" width="567" height="212" /></a> </p>
<p>There are two straight-forward lazy loads using .Load() but I’m only attaching entities for Child3 based on the results of the ‘inner query’ which uses .CreateSourceQuery() to create a queryable.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/philiphendry.wordpress.com/276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/philiphendry.wordpress.com/276/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/philiphendry.wordpress.com/276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/philiphendry.wordpress.com/276/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/philiphendry.wordpress.com/276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/philiphendry.wordpress.com/276/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/philiphendry.wordpress.com/276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/philiphendry.wordpress.com/276/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/philiphendry.wordpress.com/276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/philiphendry.wordpress.com/276/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=philiphendry.wordpress.com&blog=3012011&post=276&subd=philiphendry&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://philiphendry.wordpress.com/2009/08/28/lazy-loading-entities-referenced-by-the-returned-entities-from-a-stored-procedure-in-entity-framework-v1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/21cb73fde009d63fbcca11c16adebdfc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Phil</media:title>
		</media:content>

		<media:content url="http://philiphendry.files.wordpress.com/2009/08/image_thumb8.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
	</channel>
</rss>