<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>SQL</title>
        <link>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/category/55.aspx</link>
        <description>SQL</description>
        <language>en-US</language>
        <copyright>Shawn Weisfeld</copyright>
        <generator>Subtext Version 2.1.2.2</generator>
        <item>
            <title>&amp;quot;Why should DBA's support Azure?&amp;quot;</title>
            <link>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2010/08/18/quotwhy-should-dbas-support-azurequot.aspx</link>
            <description>&lt;p&gt;Recently I heard a question asking "Why should DBA's support Azure?" &lt;/p&gt;  &lt;p&gt;I thought I would muse a bit on it here. &lt;/p&gt;  &lt;p&gt;IMHO it boils down to the question "What is your job?"   &lt;br /&gt;I ask myself this all the time. Is it my job to write really cool code or to tune that sql query? I don't think so. I think my job is to "solve business problems". Regardless of if that problem is provide accounting the ability to do their thing or give people the ability to purchase our products, IMHO, technology is the means to that end and we as IT professionals must not forget that. IMHO our focus needs to be providing the best solutions for our customers regardless if that is Azure, a local SQL Server instance, or a XML file. They are paying us to "solve their problems". &lt;/p&gt;  &lt;p&gt;A historical perspective: &lt;/p&gt;  &lt;p&gt;I would assume back in the day when we used computers with vacuum tubes, someone had the job of replacing them. I would also assume that when we used punch cards someone had the job of feeding them into the system. However we don't see positions for those jobs any more, and if I may be so bold, I don't think the industry is worse off because of it. I think that we have chosen an industry that is constantly changing, and it is a fact of life that technologies in the long run will come and go. The only constant is there will always be change, and IMHO we need to embrace it. &lt;/p&gt;  &lt;p&gt;I think each of us needs to, every few years, look at our skills, and where the industry as a whole is going and pick a set of technologies that we feel complement our current skills and put us on a long term path that is consistent with the direction that the industry is going. Now I am not saying that Azure is going to replace the need for local DBs or DBAs. However if we constantly realign our skill sets with what the industry wants we will always be ensured that folks will come to us when they need their problems solved. IMHO, selecting IT as a career path means committing a lifetime of continual learning and continual change. &lt;/p&gt;  &lt;p&gt;These are my thoughts what are yours? Please post them below in the comments area. . . &lt;/p&gt;&lt;img src="http://www.drowningintechnicaldebt.com/ShawnWeisfeld/aggbug/759.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Shawn Weisfeld</dc:creator>
            <guid>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2010/08/18/quotwhy-should-dbas-support-azurequot.aspx</guid>
            <pubDate>Wed, 18 Aug 2010 11:39:11 GMT</pubDate>
            <wfw:comment>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/comments/759.aspx</wfw:comment>
            <comments>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2010/08/18/quotwhy-should-dbas-support-azurequot.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/comments/commentRss/759.aspx</wfw:commentRss>
            <trackback:ping>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/services/trackbacks/759.aspx</trackback:ping>
        </item>
        <item>
            <title>Could not open a connection to SQL Server</title>
            <link>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2009/07/08/could-not-open-a-connection-to-sql-server.aspx</link>
            <description>&lt;p&gt;&lt;b&gt;Problem:&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;.NET application throws the following error. &lt;/p&gt;  &lt;p&gt;&lt;i&gt;A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://drowningintechnicaldebt.com/shawnweisfeld/clip_image002_7B8D3816.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://drowningintechnicaldebt.com/shawnweisfeld/clip_image002_thumb_141CD567.gif" width="648" height="170" /&gt;&lt;/a&gt;&lt;i /&gt;&lt;/p&gt;  &lt;p&gt;&lt;i /&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Solution:&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Check SQL Server to ensure that TCP/IP is enabled. Open the List of available “Protocols for SQL Server”. You can find this in the “Computer Management” Console under “Services and Application”, “SQL Server Configuration Manager”, “SQL Server 200X Network Configuration.” After you enable TCP/IP you will need to restart the SQL Server relational engine. You can do that using the “SQL Server 200X Services” option. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://drowningintechnicaldebt.com/shawnweisfeld/clip_image004_2182E86D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://drowningintechnicaldebt.com/shawnweisfeld/clip_image004_thumb_40595C4B.jpg" width="660" height="538" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://www.drowningintechnicaldebt.com/ShawnWeisfeld/aggbug/311.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>sweisfeld</dc:creator>
            <guid>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2009/07/08/could-not-open-a-connection-to-sql-server.aspx</guid>
            <pubDate>Wed, 08 Jul 2009 16:44:01 GMT</pubDate>
            <wfw:comment>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/comments/311.aspx</wfw:comment>
            <comments>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2009/07/08/could-not-open-a-connection-to-sql-server.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/comments/commentRss/311.aspx</wfw:commentRss>
            <trackback:ping>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/services/trackbacks/311.aspx</trackback:ping>
        </item>
        <item>
            <title>Using ROW_NUMBER() to eliminate the multiplicative effects of a join</title>
            <link>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2009/07/03/using-row-number-to-eliminate-the-multiplicative-effects-of-a.aspx</link>
            <description>&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;It is a common situation to have a header/detail tables in SQL Server. Additionally sometimes you include a calculated value on the header table to make reporting easier. For Example lets say you had an SalesPerson table that had a column for total sales. Now you also have a SalesDetails table that lists every sale that the company made. The purpose of having the total sales column is that it eliminates the need to touch the larger SalesDetails table when you just need to get the total by sales person. This is a good thing until the user asks for a report that has a column for both the total sales of the sales person and a line for each of the SalesDetails. Maybe a picture will help explain.  &lt;/p&gt;  &lt;p&gt;So here is the setup. As you can see George has sold 5 items for $100 each for a total of $500. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://drowningintechnicaldebt.com/shawnweisfeld/image_0682792D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://drowningintechnicaldebt.com/shawnweisfeld/image_thumb_69995457.png" width="461" height="217" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now when we are asked to produce the report that joins these two together we get the following result:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://drowningintechnicaldebt.com/shawnweisfeld/image_3D7C5766.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://drowningintechnicaldebt.com/shawnweisfeld/image_thumb_3D102471.png" width="476" height="227" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now if someone who gets this report sums up the total sales column they get $5,000, the wrong answer. What we need to do is zero out the total sales on each row except for the first row. So our results will look something like this. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://drowningintechnicaldebt.com/shawnweisfeld/image_2D8D12A2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://drowningintechnicaldebt.com/shawnweisfeld/image_thumb_5B0E3265.png" width="484" height="231" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now the user of this report will get the same answer if they sum up the total sales column and sale amount column. So now we know what we want how do we get there in SQL Server. &lt;/p&gt;  &lt;p&gt;Well if we could number the SalesPerson Records by EmplID, then we would have the ability to zero out the records on all rows except for the first one. For example something like this. . . &lt;/p&gt;  &lt;p&gt;&lt;a href="http://drowningintechnicaldebt.com/shawnweisfeld/image_1993800C.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://drowningintechnicaldebt.com/shawnweisfeld/image_thumb_0435CAA4.png" width="505" height="211" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;ROW_NUMBER() to the rescue. MSDN defines ROW_NUMBER() as “Returns the sequential number of a row within a partition of a result set, starting at 1 for the first row in each partition.” (&lt;a title="http://msdn.microsoft.com/en-us/library/ms186734.aspx" href="http://msdn.microsoft.com/en-us/library/ms186734.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms186734.aspx&lt;/a&gt;).&lt;/p&gt;  &lt;p&gt;Here is my starting point, a standard join to put the two tables together. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://drowningintechnicaldebt.com/shawnweisfeld/image_3EB0CA78.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://drowningintechnicaldebt.com/shawnweisfeld/image_thumb_574067C8.png" width="520" height="514" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;As you can see the ROW_NUMBER function takes 2 arguments. The second is the ORDER BY, that argument tells ROW_NUMBER what order we want the results in. In this application this is irrelevant since each SalesPerson record will be the same. The first argument PARTITION BY tells SQL Server to restart the count every time it sees a change in a column or set of columns. In our case we want to restart the count for each SalesPerson. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://drowningintechnicaldebt.com/shawnweisfeld/image_47512304.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://drowningintechnicaldebt.com/shawnweisfeld/image_thumb_4B7AFAC9.png" width="537" height="504" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;So the next step is to zero out the TotalSales on all the rows except for the first one. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://drowningintechnicaldebt.com/shawnweisfeld/image_7BC1CF7F.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://drowningintechnicaldebt.com/shawnweisfeld/image_thumb_0F02861F.png" width="543" height="535" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Yes! Now our users can sum up the TotalSales column or the SaleAmt column and get the same answer! Another happy report user = another happy developer!&lt;/p&gt;&lt;img src="http://www.drowningintechnicaldebt.com/ShawnWeisfeld/aggbug/309.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>sweisfeld</dc:creator>
            <guid>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2009/07/03/using-row-number-to-eliminate-the-multiplicative-effects-of-a.aspx</guid>
            <pubDate>Fri, 03 Jul 2009 17:33:46 GMT</pubDate>
            <wfw:comment>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/comments/309.aspx</wfw:comment>
            <comments>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2009/07/03/using-row-number-to-eliminate-the-multiplicative-effects-of-a.aspx#feedback</comments>
            <slash:comments>6</slash:comments>
            <wfw:commentRss>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/comments/commentRss/309.aspx</wfw:commentRss>
            <trackback:ping>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/services/trackbacks/309.aspx</trackback:ping>
        </item>
        <item>
            <title>SQL CLR: Query the file system to get a list of folders</title>
            <link>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2009/06/11/sql-clr-query-the-file-system-to-get-a-list.aspx</link>
            <description>&lt;p&gt;Today was a good day for questions, got one asking how to query the file system from sql server. See they have a list of network shares that they want to find out what folders are in each. SQL CLR to the rescue. . . &lt;/p&gt;  &lt;p&gt;First lets write a Table Valued Function to get a list of folders. I chose a Table Valued Function so I can join it to a list of paths to search in sql server. Remember that since we are leaving the confines of the SQL Server to get data from the disk we need to elevate our permission, we are also impersonating a domain account as they have access to external resources. &lt;/p&gt;  &lt;p&gt;here is the code for the Table Valued Function:&lt;/p&gt; &lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;  &lt;div class="csharpcode"&gt;   &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Data;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Data.SqlClient;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Data.SqlTypes;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; Microsoft.SqlServer.Server;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Collections;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Security.Principal;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt; &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; UserDefinedFunctions&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;    &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;    &lt;span class="rem"&gt;/// Get a list of all the folders in a given path, for a given number of levels deep&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;    &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;    &lt;span class="rem"&gt;/// &amp;lt;param name="path"&amp;gt;&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;    &lt;span class="rem"&gt;/// &amp;lt;param name="levels"&amp;gt;&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;    &lt;span class="rem"&gt;/// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;    [SqlFunction(FillRowMethodName = &lt;span class="str"&gt;"FillRow"&lt;/span&gt;, TableDefinition = &lt;span class="str"&gt;"directory nvarchar(4000)"&lt;/span&gt;, DataAccess=DataAccessKind.Read)]&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; IEnumerable Folders(String path, &lt;span class="kwrd"&gt;int&lt;/span&gt; levels)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;        WindowsImpersonationContext impersonatedIdentity = &lt;span class="kwrd"&gt;null&lt;/span&gt;;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  22:  &lt;/span&gt;        List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; results = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;();&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  23:  &lt;/span&gt; &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  24:  &lt;/span&gt;        &lt;span class="kwrd"&gt;try&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  25:  &lt;/span&gt;        {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  26:  &lt;/span&gt;            &lt;span class="rem"&gt;//impersonate the user that is executing me in sql server&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  27:  &lt;/span&gt;            impersonatedIdentity = SqlContext.WindowsIdentity.Impersonate();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  28:  &lt;/span&gt; &lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  29:  &lt;/span&gt;            &lt;span class="rem"&gt;//Get the data&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  30:  &lt;/span&gt;            GetDirectories(results, path, levels);&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  31:  &lt;/span&gt;        }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  32:  &lt;/span&gt;        &lt;span class="kwrd"&gt;finally&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  33:  &lt;/span&gt;        {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  34:  &lt;/span&gt;            &lt;span class="rem"&gt;//undo the impersonation&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  35:  &lt;/span&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (impersonatedIdentity != &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  36:  &lt;/span&gt;            {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  37:  &lt;/span&gt;                impersonatedIdentity.Undo();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  38:  &lt;/span&gt;            }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  39:  &lt;/span&gt;        }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  40:  &lt;/span&gt; &lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  41:  &lt;/span&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; results;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  42:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  43:  &lt;/span&gt; &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  44:  &lt;/span&gt;    &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  45:  &lt;/span&gt;    &lt;span class="rem"&gt;/// Recursivly dig through the file system getting data&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  46:  &lt;/span&gt;    &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  47:  &lt;/span&gt;    &lt;span class="rem"&gt;/// &amp;lt;param name="results"&amp;gt;List of the results&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  48:  &lt;/span&gt;    &lt;span class="rem"&gt;/// &amp;lt;param name="path"&amp;gt;Current Path we are looking into&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  49:  &lt;/span&gt;    &lt;span class="rem"&gt;/// &amp;lt;param name="levels"&amp;gt;Number of levels left to dig down&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  50:  &lt;/span&gt;    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; GetDirectories(List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; results, &lt;span class="kwrd"&gt;string&lt;/span&gt; path, &lt;span class="kwrd"&gt;int&lt;/span&gt; levels)&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  51:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  52:  &lt;/span&gt;        &lt;span class="rem"&gt;//are we at the bottom of the query&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  53:  &lt;/span&gt;        &lt;span class="kwrd"&gt;if&lt;/span&gt; (levels &amp;gt; 0)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  54:  &lt;/span&gt;        {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  55:  &lt;/span&gt;            &lt;span class="rem"&gt;//append on the slash if we dont have it&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  56:  &lt;/span&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (!path.EndsWith(&lt;span class="str"&gt;"\\"))&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  57:  &lt;/span&gt;            {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  58:  &lt;/span&gt;                path = path + "\\&lt;span class="str"&gt;";&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  59:  &lt;/span&gt;            }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  60:  &lt;/span&gt; &lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  61:  &lt;/span&gt;            try&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  62:  &lt;/span&gt;            {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  63:  &lt;/span&gt;                //get a list of all the folders under the current path&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  64:  &lt;/span&gt;                foreach (string folder in System.IO.Directory.GetDirectories(path, "*&lt;span class="str"&gt;", System.IO.SearchOption.TopDirectoryOnly))&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  65:  &lt;/span&gt;                {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  66:  &lt;/span&gt;                    //add each to the results, then dig down one more level&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  67:  &lt;/span&gt;                    results.Add(folder);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  68:  &lt;/span&gt;                    GetDirectories(results, folder, levels - 1);&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  69:  &lt;/span&gt;                }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  70:  &lt;/span&gt;            }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  71:  &lt;/span&gt;            catch (UnauthorizedAccessException ex)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  72:  &lt;/span&gt;            {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  73:  &lt;/span&gt;                //If we dont have access to a folder, just report that back in the result set&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  74:  &lt;/span&gt;                results.Add(ex.Message);&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  75:  &lt;/span&gt;            }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  76:  &lt;/span&gt;        }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  77:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  78:  &lt;/span&gt; &lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  79:  &lt;/span&gt;    /// &amp;lt;summary&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  80:  &lt;/span&gt;    /// convert one of our Enumerable objects into a data row&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  81:  &lt;/span&gt;    /// &amp;lt;/summary&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  82:  &lt;/span&gt;    /// &amp;lt;param name="obj&lt;span class="str"&gt;"&amp;gt;&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  83:  &lt;/span&gt;    /// &amp;lt;param name="directory"&amp;gt;&amp;lt;/param&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  84:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; FillRow(Object obj, &lt;span class="kwrd"&gt;out&lt;/span&gt; SqlChars directory)&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  85:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  86:  &lt;/span&gt;        directory = &lt;span class="kwrd"&gt;new&lt;/span&gt; SqlChars(obj.ToString());&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  87:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  88:  &lt;/span&gt;};&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;I created a table (SearchPaths) that contains a list of all the paths that I want to search:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://drowningintechnicaldebt.com/shawnweisfeld/image_2E8912F6.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://drowningintechnicaldebt.com/shawnweisfeld/image_thumb_067663D7.png" width="600" height="349" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;Now I can just join the list of paths to search with the function and I have everything I was looking for:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://drowningintechnicaldebt.com/shawnweisfeld/image_44234B93.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://drowningintechnicaldebt.com/shawnweisfeld/image_thumb_43B7189E.png" width="674" height="466" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;If you are getting security exceptions and the like take a look at the slides from the CLR talk I gave a PASS Summit 2008, they should get you moving in the right direction. &lt;/p&gt;

&lt;p&gt;&lt;a title="http://drowningintechnicaldebt.com/blogs/shawnweisfeld/archive/2008/11/23/sql-pass-2008-talk.aspx" href="http://drowningintechnicaldebt.com/blogs/shawnweisfeld/archive/2008/11/23/sql-pass-2008-talk.aspx"&gt;http://drowningintechnicaldebt.com/blogs/shawnweisfeld/archive/2008/11/23/sql-pass-2008-talk.aspx&lt;/a&gt;&lt;/p&gt;&lt;img src="http://www.drowningintechnicaldebt.com/ShawnWeisfeld/aggbug/301.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>sweisfeld</dc:creator>
            <guid>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2009/06/11/sql-clr-query-the-file-system-to-get-a-list.aspx</guid>
            <pubDate>Thu, 11 Jun 2009 10:12:49 GMT</pubDate>
            <wfw:comment>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/comments/301.aspx</wfw:comment>
            <comments>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2009/06/11/sql-clr-query-the-file-system-to-get-a-list.aspx#feedback</comments>
            <wfw:commentRss>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/comments/commentRss/301.aspx</wfw:commentRss>
            <trackback:ping>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/services/trackbacks/301.aspx</trackback:ping>
        </item>
        <item>
            <title>SQL Server: Who am I?</title>
            <link>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2009/06/11/sql-server-who-am-i.aspx</link>
            <description>&lt;p&gt;Got a question today. How do I tell what user my sql server query is running as? Well you just ask. &lt;/p&gt;  &lt;p&gt;Using the USER_NAME() function, without passing it an id, finds the name of the current user. &lt;/p&gt;  &lt;p&gt;&lt;a title="http://msdn.microsoft.com/en-us/library/ms188014.aspx" href="http://msdn.microsoft.com/en-us/library/ms188014.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms188014.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Using the SUSER_NAME() function, gets me the login identification name of the user.&lt;/p&gt;  &lt;p&gt;&lt;a title="http://msdn.microsoft.com/en-us/library/ms187934.aspx" href="http://msdn.microsoft.com/en-us/library/ms187934.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms187934.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;Here is an example of each, using both a regular sql server login (left) and windows authentication (right)&lt;/p&gt;  &lt;p&gt;&lt;a href="http://drowningintechnicaldebt.com/shawnweisfeld/image_10EEF353.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://drowningintechnicaldebt.com/shawnweisfeld/image_thumb_61BD07BB.png" width="646" height="258" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;Now that I know who I am, why not be someone else. . . In this example I change the context that I am running under with the “EXECUTE AS LOGIN” statement, then I revert back using . . . wait for it. . . the “REVERT” statement. &lt;/p&gt;  &lt;p&gt;EXECUTE AS: &lt;a title="http://msdn.microsoft.com/en-us/library/ms181362.aspx" href="http://msdn.microsoft.com/en-us/library/ms181362.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms181362.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;REVERT: &lt;a title="http://msdn.microsoft.com/en-us/library/ms178632.aspx" href="http://msdn.microsoft.com/en-us/library/ms178632.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms178632.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://drowningintechnicaldebt.com/shawnweisfeld/image_635DADC2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://drowningintechnicaldebt.com/shawnweisfeld/image_thumb_7461DBA5.png" width="332" height="567" /&gt;&lt;/a&gt;  &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;and they say getting to know ones self is hard. . . &lt;/p&gt;&lt;img src="http://www.drowningintechnicaldebt.com/ShawnWeisfeld/aggbug/300.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>sweisfeld</dc:creator>
            <guid>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2009/06/11/sql-server-who-am-i.aspx</guid>
            <pubDate>Thu, 11 Jun 2009 08:48:30 GMT</pubDate>
            <wfw:comment>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/comments/300.aspx</wfw:comment>
            <comments>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2009/06/11/sql-server-who-am-i.aspx#feedback</comments>
            <wfw:commentRss>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/comments/commentRss/300.aspx</wfw:commentRss>
            <trackback:ping>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/services/trackbacks/300.aspx</trackback:ping>
        </item>
        <item>
            <title>SQL Server 2008 Access is Denied Error During Install</title>
            <link>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2009/06/08/sql-server-2008-access-is-denied-error-during-install.aspx</link>
            <description>&lt;p&gt;&lt;strong&gt;Problem&lt;/strong&gt;: when installing SQL Server 2008 you get an Access is Denied Error.&lt;/p&gt;
&lt;p&gt;Here is the error you get during install. . . . &lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.drowningintechnicaldebt.com/shawnweisfeld/clip_image002_5BC32399.jpg"&gt;&lt;img style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title="clip_image002" border="0" alt="clip_image002" width="413" height="116" src="/shawnweisfeld/clip_image002_thumb_2D699DEC.jpg" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Fix&lt;/strong&gt;: Check your Local Security Policy, you need to ensure that Administrators have “Debug programs” permission (Security Settings | Local Policies | User Rights Assignment)&lt;/p&gt;
&lt;p&gt;More information can be found in the following articles:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=390424"&gt;https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=390424&lt;/a&gt; &lt;span style="COLOR: red"&gt;(If you have had this error please follow this link and vote that it gets fixed in connect)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://social.msdn.microsoft.com/forums/en-US/sqlsetupandupgrade/thread/ed4514fa-8d1d-4383-bbdf-fb06bfbad106/"&gt;http://social.msdn.microsoft.com/forums/en-US/sqlsetupandupgrade/thread/ed4514fa-8d1d-4383-bbdf-fb06bfbad106/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face=""&gt;&lt;a href="http://support.microsoft.com/?kbid=2000257"&gt;http://support.microsoft.com/?kbid=2000257&lt;/a&gt;&lt;/font&gt;&lt;/p&gt;&lt;img src="http://www.drowningintechnicaldebt.com/ShawnWeisfeld/aggbug/299.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Shawn Weisfeld</dc:creator>
            <guid>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2009/06/08/sql-server-2008-access-is-denied-error-during-install.aspx</guid>
            <pubDate>Mon, 08 Jun 2009 15:33:00 GMT</pubDate>
            <wfw:comment>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/comments/299.aspx</wfw:comment>
            <comments>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2009/06/08/sql-server-2008-access-is-denied-error-during-install.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/comments/commentRss/299.aspx</wfw:commentRss>
            <trackback:ping>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/services/trackbacks/299.aspx</trackback:ping>
        </item>
        <item>
            <title>Cross Tab Queries in SQL Server V3</title>
            <link>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2009/03/10/cross-tab-queries-in-sql-server-v3.aspx</link>
            <description>&lt;p&gt;Using the example from my last post (&lt;a title="Cross Tab Queries in SQL Server V2" href="http://drowningintechnicaldebt.com/blogs/shawnweisfeld/archive/2009/03/09/pivot-cross-tab-queries-in-sql-server-v2.aspx"&gt;Cross Tab Queries in SQL Server V2&lt;/a&gt;) I was asked to figure out how to make the query more dynamic. The only way to make it truly dynamic (i.e. return a different # of columns) would be to use dynamic SQL. However lets say you want to do a sliding window of 5 years for reporting. . . . Here is an example that utilizes a table valued function. . . . .&lt;/p&gt;  &lt;p&gt;CREATE FUNCTION tvfTest    &lt;br /&gt;(     &lt;br /&gt;    @year int     &lt;br /&gt;)     &lt;br /&gt;RETURNS     &lt;br /&gt;@return TABLE     &lt;br /&gt;(     &lt;br /&gt;    ClientID int,     &lt;br /&gt;    year1 decimal(18, 0),     &lt;br /&gt;    year2 decimal(18, 0),     &lt;br /&gt;    year3 decimal(18, 0),     &lt;br /&gt;    year4 decimal(18, 0),     &lt;br /&gt;    year5 decimal(18, 0)     &lt;br /&gt;)     &lt;br /&gt;AS     &lt;br /&gt;BEGIN &lt;/p&gt;  &lt;p&gt;INSERT INTO @return    &lt;br /&gt;SELECT [ClientID], year1 AS year1, year2 AS year2, year3 AS year3, year4 AS year4, year5 AS year5     &lt;br /&gt;FROM     &lt;br /&gt;(     &lt;br /&gt;SELECT [ClientID],     &lt;br /&gt;    CASE WHEN DATEPART(yy, [SalesDate]) = @year THEN 'year1'     &lt;br /&gt;         WHEN DATEPART(yy, [SalesDate]) - 1 = @year THEN 'year2'     &lt;br /&gt;         WHEN DATEPART(yy, [SalesDate]) - 2 = @year THEN 'year3'     &lt;br /&gt;         WHEN DATEPART(yy, [SalesDate]) - 3 = @year THEN 'year4'     &lt;br /&gt;         WHEN DATEPART(yy, [SalesDate]) - 4 = @year THEN 'year5'     &lt;br /&gt;         ELSE 'outofrange' END AS SalesYear,     &lt;br /&gt;   [SalesAmount]     &lt;br /&gt;FROM [Sales]) N     &lt;br /&gt;PIVOT     &lt;br /&gt;(     &lt;br /&gt;SUM ([SalesAmount])     &lt;br /&gt;FOR SalesYear IN     &lt;br /&gt;(     &lt;br /&gt;[year1], [year2], [year3], [year4], [year5] )     &lt;br /&gt;) AS pvt &lt;/p&gt;  &lt;p&gt;RETURN &lt;/p&gt;  &lt;p&gt;END    &lt;br /&gt;GO&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;You then call it like this:&lt;/p&gt;  &lt;p&gt;SELECT *    &lt;br /&gt;FROM tvfTest(2006)&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;table cellspacing="0" cellpadding="0" width="400" border="1"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td width="77"&gt;ClientID&lt;/td&gt;        &lt;td width="65"&gt;year1&lt;/td&gt;        &lt;td width="64"&gt;year2&lt;/td&gt;        &lt;td width="64"&gt;year3&lt;/td&gt;        &lt;td width="64"&gt;year4&lt;/td&gt;        &lt;td width="64"&gt;year5&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td width="77"&gt;1&lt;/td&gt;        &lt;td width="65"&gt;100&lt;/td&gt;        &lt;td width="64"&gt;200&lt;/td&gt;        &lt;td width="64"&gt;300&lt;/td&gt;        &lt;td width="64"&gt;400&lt;/td&gt;        &lt;td width="64"&gt;NULL&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td width="77"&gt;2&lt;/td&gt;        &lt;td width="68"&gt;150&lt;/td&gt;        &lt;td width="72"&gt;250&lt;/td&gt;        &lt;td width="77"&gt;250&lt;/td&gt;        &lt;td width="83"&gt;250&lt;/td&gt;        &lt;td width="90"&gt;NULL&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;&lt;img src="http://www.drowningintechnicaldebt.com/ShawnWeisfeld/aggbug/284.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>sweisfeld</dc:creator>
            <guid>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2009/03/10/cross-tab-queries-in-sql-server-v3.aspx</guid>
            <pubDate>Tue, 10 Mar 2009 07:07:36 GMT</pubDate>
            <wfw:comment>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/comments/284.aspx</wfw:comment>
            <comments>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2009/03/10/cross-tab-queries-in-sql-server-v3.aspx#feedback</comments>
            <wfw:commentRss>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/comments/commentRss/284.aspx</wfw:commentRss>
            <trackback:ping>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/services/trackbacks/284.aspx</trackback:ping>
        </item>
        <item>
            <title>Pivot/Cross Tab Queries in SQL Server V2</title>
            <link>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2009/03/10/pivot-cross-tab-queries-in-sql-server-v2.aspx</link>
            <description>&lt;p&gt;Back in 2008 I blogged about Pivot/Cross Tab Queries in SQL Server (&lt;a href="http://drowningintechnicaldebt.com/blogs/shawnweisfeld/archive/2008/01/21/pivot-cross-tab-queries-in-sql-server.aspx" mce_href="http://drowningintechnicaldebt.com/blogs/shawnweisfeld/archive/2008/01/21/pivot-cross-tab-queries-in-sql-server.aspx"&gt;http://drowningintechnicaldebt.com/blogs/shawnweisfeld/archive/2008/01/21/pivot-cross-tab-queries-in-sql-server.aspx&lt;/a&gt;). I was asked for another example so here goes:&lt;/p&gt;&lt;pre class="csharpcode"&gt;--Sample Sales &lt;span class="kwrd"&gt;Table&lt;/span&gt;
&lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;TABLE&lt;/span&gt; [dbo].[Sales](
    [ClientID] [&lt;span class="kwrd"&gt;int&lt;/span&gt;] &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;NULL&lt;/span&gt;,
    [SalesDate] [datetime] &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;NULL&lt;/span&gt;,
    [SalesAmount] [&lt;span class="kwrd"&gt;decimal&lt;/span&gt;](18, 0) &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;NULL&lt;/span&gt;
) &lt;span class="kwrd"&gt;ON&lt;/span&gt; [&lt;span class="kwrd"&gt;PRIMARY&lt;/span&gt;]

--Added sample &lt;span class="kwrd"&gt;data&lt;/span&gt;
&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; [ClientID]
      ,[SalesDate]
      ,[SalesAmount]
  &lt;span class="kwrd"&gt;FROM&lt;/span&gt; [Sales]&lt;/pre&gt;
&lt;table class="" cellspacing="0" cellpadding="0" border="1"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td class="" width="64"&gt;ClientID&lt;/td&gt;
&lt;td class="" width="64"&gt;SalesDate&lt;/td&gt;
&lt;td class="" width="89"&gt;SalesAmount&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;1&lt;/td&gt;
&lt;td class=""&gt;1/1/2006&lt;/td&gt;
&lt;td class=""&gt;100&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;1&lt;/td&gt;
&lt;td class=""&gt;1/1/2007&lt;/td&gt;
&lt;td class=""&gt;200&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;1&lt;/td&gt;
&lt;td class=""&gt;1/1/2008&lt;/td&gt;
&lt;td class=""&gt;300&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;1&lt;/td&gt;
&lt;td class=""&gt;1/1/2009&lt;/td&gt;
&lt;td class=""&gt;400&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;2&lt;/td&gt;
&lt;td class=""&gt;1/1/2006&lt;/td&gt;
&lt;td class=""&gt;150&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;2&lt;/td&gt;
&lt;td class=""&gt;1/1/2007&lt;/td&gt;
&lt;td class=""&gt;250&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;2&lt;/td&gt;
&lt;td class=""&gt;1/1/2008&lt;/td&gt;
&lt;td class=""&gt;250&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;2&lt;/td&gt;
&lt;td class=""&gt;1/1/2009&lt;/td&gt;
&lt;td class=""&gt;250&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;pre class="csharpcode"&gt;--&lt;span class="kwrd"&gt;Create&lt;/span&gt; &lt;span class="kwrd"&gt;view&lt;/span&gt; &lt;span class="kwrd"&gt;to&lt;/span&gt; report Sales &lt;span class="kwrd"&gt;by&lt;/span&gt; &lt;span class="kwrd"&gt;Year&lt;/span&gt; &lt;span class="kwrd"&gt;by&lt;/span&gt; Client
&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; [ClientID]
      ,DATEPART(yy, [SalesDate]) &lt;span class="kwrd"&gt;AS&lt;/span&gt; SalesYear
      ,&lt;span class="kwrd"&gt;SUM&lt;/span&gt;([SalesAmount]) &lt;span class="kwrd"&gt;AS&lt;/span&gt; [SalesAmount]
  &lt;span class="kwrd"&gt;FROM&lt;/span&gt; [Sales]
&lt;span class="kwrd"&gt;GROUP&lt;/span&gt; &lt;span class="kwrd"&gt;BY&lt;/span&gt; [ClientID]
      ,DATEPART(yy, [SalesDate])&lt;/pre&gt;
&lt;table class="" cellspacing="0" cellpadding="0" border="1"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td class="" width="64"&gt;ClientID&lt;/td&gt;
&lt;td class="" width="68"&gt;SalesYear&lt;/td&gt;
&lt;td class="" width="89"&gt;SalesAmount&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;1&lt;/td&gt;
&lt;td class=""&gt;2006&lt;/td&gt;
&lt;td class=""&gt;100&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;2&lt;/td&gt;
&lt;td class=""&gt;2006&lt;/td&gt;
&lt;td class=""&gt;150&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;1&lt;/td&gt;
&lt;td class=""&gt;2007&lt;/td&gt;
&lt;td class=""&gt;200&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;2&lt;/td&gt;
&lt;td class=""&gt;2007&lt;/td&gt;
&lt;td class=""&gt;250&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;1&lt;/td&gt;
&lt;td class=""&gt;2008&lt;/td&gt;
&lt;td class=""&gt;300&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;2&lt;/td&gt;
&lt;td class=""&gt;2008&lt;/td&gt;
&lt;td class=""&gt;250&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;1&lt;/td&gt;
&lt;td class=""&gt;2009&lt;/td&gt;
&lt;td class=""&gt;400&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;2&lt;/td&gt;
&lt;td class=""&gt;2009&lt;/td&gt;
&lt;td class=""&gt;250&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;pre class="csharpcode"&gt;--&lt;span class="kwrd"&gt;for&lt;/span&gt; &lt;span class="kwrd"&gt;sql&lt;/span&gt; server 2005 +
--Pivot &lt;span class="kwrd"&gt;to&lt;/span&gt; report sales &lt;span class="kwrd"&gt;by&lt;/span&gt; client &lt;span class="kwrd"&gt;over&lt;/span&gt; years
&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; [ClientID], [2006] &lt;span class="kwrd"&gt;AS&lt;/span&gt; year2006, [2007] &lt;span class="kwrd"&gt;AS&lt;/span&gt; year2007, [2008] &lt;span class="kwrd"&gt;AS&lt;/span&gt; year2008, [2009] &lt;span class="kwrd"&gt;AS&lt;/span&gt; year2009
&lt;span class="kwrd"&gt;FROM&lt;/span&gt; 
(
 &lt;span class="kwrd"&gt;SELECT&lt;/span&gt; [ClientID], DATEPART(yy, [SalesDate]) &lt;span class="kwrd"&gt;AS&lt;/span&gt; SalesYear, [SalesAmount]
 &lt;span class="kwrd"&gt;FROM&lt;/span&gt; [Sales]) N
PIVOT
(
&lt;span class="kwrd"&gt;SUM&lt;/span&gt; ([SalesAmount])
&lt;span class="kwrd"&gt;FOR&lt;/span&gt; SalesYear &lt;span class="kwrd"&gt;IN&lt;/span&gt;
( 
 [2006], [2007], [2008], [2009] )
) &lt;span class="kwrd"&gt;AS&lt;/span&gt; pvt
&lt;span class="kwrd"&gt;ORDER&lt;/span&gt; &lt;span class="kwrd"&gt;BY&lt;/span&gt; [ClientID]&lt;/pre&gt;
&lt;table class="" cellspacing="0" cellpadding="0" border="1"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td class="" width="64"&gt;ClientID&lt;/td&gt;
&lt;td class="" width="64"&gt;year2006&lt;/td&gt;
&lt;td class="" width="64"&gt;year2007&lt;/td&gt;
&lt;td class="" width="64"&gt;year2008&lt;/td&gt;
&lt;td class="" width="64"&gt;year2009&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;1&lt;/td&gt;
&lt;td class=""&gt;100&lt;/td&gt;
&lt;td class=""&gt;200&lt;/td&gt;
&lt;td class=""&gt;300&lt;/td&gt;
&lt;td class=""&gt;400&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;2&lt;/td&gt;
&lt;td class=""&gt;150&lt;/td&gt;
&lt;td class=""&gt;250&lt;/td&gt;
&lt;td class=""&gt;250&lt;/td&gt;
&lt;td class=""&gt;250&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;img src="http://www.drowningintechnicaldebt.com/ShawnWeisfeld/aggbug/283.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>sweisfeld</dc:creator>
            <guid>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2009/03/10/pivot-cross-tab-queries-in-sql-server-v2.aspx</guid>
            <pubDate>Tue, 10 Mar 2009 05:32:00 GMT</pubDate>
            <wfw:comment>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/comments/283.aspx</wfw:comment>
            <comments>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2009/03/10/pivot-cross-tab-queries-in-sql-server-v2.aspx#feedback</comments>
            <slash:comments>5</slash:comments>
            <wfw:commentRss>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/comments/commentRss/283.aspx</wfw:commentRss>
            <trackback:ping>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/services/trackbacks/283.aspx</trackback:ping>
        </item>
        <item>
            <title>What do your error messages reveal?</title>
            <link>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2009/03/09/what-do-your-error-messages-reveal.aspx</link>
            <description>&lt;p mce_keep="true"&gt;I know that most of you all know this already, but I figured it was worth a blog post since I just saw this from &lt;a href="http://www.autosite.com/"&gt;http://www.autosite.com&lt;/a&gt;. I got this very informative error message back when using their site earlier. . . &lt;/p&gt;
&lt;p mce_keep="true"&gt;Query Of Queries runtime error.&lt;br /&gt;Expected type STRING but encountered type NULL on the left of the LIKE condition  &lt;br /&gt;The error occurred in D:\INETPUB\wwwroot\content\Research\kbb\act_valueReport.cfm: line 74 &lt;br /&gt;Called from D:\INETPUB\WWWROOT\content\Research\kbb\index.cfm: line 21&lt;br /&gt;72 : &lt;br /&gt;73 :  &amp;lt;cfmodule template="mod_kbbtable.cfm" width="#kbbModTableWidth#"&amp;gt;&lt;br /&gt;74 :  &amp;lt;cfquery dbtype="query" name="qEquip"&amp;gt;&lt;br /&gt;75 :  SELECT * FROM valueReport.Equipments WHERE GroupCode LIKE 'M' ORDER BY DisplayOrder&lt;br /&gt;76 :  &amp;lt;/cfquery&amp;gt;&lt;/p&gt;
&lt;p mce_keep="true"&gt;While it is important for us as developers to log this type of information, there is NO reason for us to show it to our customers. Now I know table names, physical paths, and other good stuff. In your asp.net applicaitons make sure you set your customer errors to “On” (&lt;a href="http://msdn.microsoft.com/en-us/library/h0hfz6fc.aspx"&gt;http://msdn.microsoft.com/en-us/library/h0hfz6fc.aspx&lt;/a&gt;). You also want to make sure that you have logging so that you as the developer can triage errors. &lt;/p&gt;
&lt;p mce_keep="true"&gt;Oh and here is a BONUS TIP: Don’t use Select *, in most cases you don’t need all the columns and there is no reason to have the DB send them all back. . . . &lt;/p&gt;
&lt;p mce_keep="true"&gt;Let’s start a campaign to call out any website that we see on the internet that doesn’t properly hide their dirty laundry. &lt;br /&gt;&lt;/p&gt;&lt;img src="http://www.drowningintechnicaldebt.com/ShawnWeisfeld/aggbug/281.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>sweisfeld</dc:creator>
            <guid>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2009/03/09/what-do-your-error-messages-reveal.aspx</guid>
            <pubDate>Mon, 09 Mar 2009 17:46:00 GMT</pubDate>
            <wfw:comment>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/comments/281.aspx</wfw:comment>
            <comments>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2009/03/09/what-do-your-error-messages-reveal.aspx#feedback</comments>
            <wfw:commentRss>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/comments/commentRss/281.aspx</wfw:commentRss>
            <trackback:ping>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/services/trackbacks/281.aspx</trackback:ping>
        </item>
        <item>
            <title>SQL PASS 2008 Feedback</title>
            <link>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2008/12/16/sql-pass-2008-feedback.aspx</link>
            <description>&lt;p mce_keep="true"&gt;I wanted to share the feedback that I got from my presentation this year at the PASS Summit. (&lt;a href="http://drowningintechnicaldebt.com/blogs/shawnweisfeld/archive/2008/11/23/sql-pass-2008-talk.aspx"&gt;http://drowningintechnicaldebt.com/blogs/shawnweisfeld/archive/2008/11/23/sql-pass-2008-talk.aspx&lt;/a&gt;) Again thank you to all that attended, and &lt;u&gt;&lt;em&gt;a special thank you to those that provided feedback&lt;/em&gt;&lt;/u&gt; it is an invaluable tool to help presenters improve over time. (BTW these are all the comments, I did not filter them at all)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Overall 4.44 out of 5&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What is your overall evaluation of the session? 4.5&lt;/strong&gt;&lt;br /&gt;Difficult topic to present. He did a good job.&lt;br /&gt;Good content. Bonus content at the end took it to the next level without getting exotic. Wirht the time to sit through.&lt;br /&gt;Interesting, but a little slow at the start.&lt;br /&gt;Outstanding!&lt;br /&gt;Speaker stands in the dark. Have some light on him.&lt;br /&gt;This was the best session I attended. The presenter's pace was excellent and his lecture was well-thought out. He's obviosly comfortable speaking in front of a group.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;How would you rate the usefulness of the information presented in your day-to-day environment? 4.08&lt;br /&gt;&lt;/strong&gt;Good selections.&lt;br /&gt;The content was in an area we don't actively use, but don't want to avoid. This gave me a solid foot in the door as a DBA / Developer and exposed me to different facets to consider.&lt;br /&gt;Samples should be more real world on what should be done in a CLR versus T-SQL.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;How would you rate the Speaker's presentation skills? 4.5&lt;br /&gt;&lt;/strong&gt;Speaker is very smart about what to say.&lt;br /&gt;Great speaking skills, kept the content flowing within the time alloted and managed to put in very valuable bonus content at the end. Great posative attitude.&lt;br /&gt;He directed the audience well, even when we wanted to jump ahead of him.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;How would you rate the Speaker's knowledge of the subject? 4.67&lt;/strong&gt;&lt;br /&gt;Obviously well versed on the topic, and for the most part able to take questions and resolve and answer that made sense.&lt;br /&gt;My favorite part was that he showed errors we were likely to see and how to recover. No other presenter I've seen did this.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;How would you rate the accuracy of the session title, description and experience level to the actual session? 4.5&lt;br /&gt;&lt;/strong&gt;Reletively hard to misunderstand this. Could have added the word "USING". NOt that there was a lack of space for it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;How would you rate the amount of time allocated to cover the topic/session? 4.5&lt;br /&gt;&lt;/strong&gt;A bit tight, but the content fit into the space allowed and the speaker stayed on topic to assure it worked.&lt;br /&gt;And he did a great job of staying within his allocated time.&lt;br /&gt;Great time management and ease of dealing with questions from the floor.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;How would you rate the quality of the presentaion materials? 4.33&lt;br /&gt;&lt;/strong&gt;Good code examples demonstrated. Excellent use of realtime erros and troubleshooting.&lt;br /&gt;stop showing the same thing on PPT and in code. it is not useful! You would save a lot of time.&lt;br /&gt;He had all of his scripts pasted into his powerpoint for easy reading. Again, no other presenter did this.&lt;br /&gt;Just leave most in power point.  with just one or two real samples&lt;br /&gt;Good examples; building on the go.&lt;/p&gt;&lt;img src="http://www.drowningintechnicaldebt.com/ShawnWeisfeld/aggbug/275.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>sweisfeld</dc:creator>
            <guid>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2008/12/16/sql-pass-2008-feedback.aspx</guid>
            <pubDate>Tue, 16 Dec 2008 06:34:00 GMT</pubDate>
            <wfw:comment>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/comments/275.aspx</wfw:comment>
            <comments>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2008/12/16/sql-pass-2008-feedback.aspx#feedback</comments>
            <wfw:commentRss>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/comments/commentRss/275.aspx</wfw:commentRss>
            <trackback:ping>http://www.drowningintechnicaldebt.com/ShawnWeisfeld/services/trackbacks/275.aspx</trackback:ping>
        </item>
    </channel>
</rss>
