<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/">
  <channel>
    <title>SQLblog.com - The SQL Server blog spot on the web</title>
    <description>&lt;P&gt;THE SQL Server Blog Spot on the Web&lt;/P&gt;</description>
    <link>http://sqlblog.com/roller/default.aspx</link>
    <docs>http://backend.userland.com/rss</docs>
    <generator>Community Server v2.0 (http://www.communityserver.org)</generator>
    <item>
      <title>Manipulate XML data with non-xml columns and not using variable</title>
      <description>&lt;p&gt;Some time ago, I displayed how to work with XML data when searching for data stored in a XML column. &lt;br /&gt;
Here &lt;a title="Some XML search approaches" href="http://weblogs.sqlteam.com/peterl/archive/2008/03/26/Some-XML-search-approaches.aspx"&gt;Some XML search approaches&lt;/a&gt; and here &lt;a title="Updated XML search (test case with variables)" href="http://weblogs.sqlteam.com/peterl/archive/2008/09/01/Updated-XML-search-test-case-with-variables.aspx"&gt;Updated XML search (test case with variables)&lt;/a&gt;. &lt;br /&gt;
&lt;br /&gt;
Today I thought I should demonstrate how to insert and update XML columns with data from other columns and not using variables. Well, I do have some examples of using variables in here because I wanted to display the core difference. &lt;br /&gt;
And this is my first blog post (not counting the previous announcement) since I become a MVP, I thought this blog post should be about something necessary. &lt;br /&gt;
&lt;br /&gt;
Much of the XML manipulations I have made by trials and errors, because I haven’t found a single good source of information about these things. If you do know of such information, please comment. &lt;br /&gt;
&lt;br /&gt;
First, we create a sample table to hold some important data, like this &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;CREATE&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt; &lt;span style="COLOR:blue;"&gt;TABLE    &lt;/span&gt;#Sample &lt;br /&gt;
&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="mso-tab-count:1;"&gt;                &lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:gray;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;( &lt;br /&gt;
&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;                    RowID &lt;span style="COLOR:blue;"&gt;INT&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;IDENTITY&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;1&lt;span style="COLOR:gray;"&gt;,&lt;/span&gt; 1&lt;span style="COLOR:gray;"&gt;)&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;PRIMARY&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;KEY&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;CLUSTERED&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;, &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;                    &lt;/span&gt;MemberID &lt;span style="COLOR:blue;"&gt;INT&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;, &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;                    &lt;/span&gt;MemberData &lt;span style="COLOR:blue;"&gt;XML &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;                &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;) &lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;INSERT  &lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;#Sample &lt;br /&gt;
&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;SELECT  &lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;1&lt;span style="COLOR:gray;"&gt;,&lt;/span&gt; &lt;span style="COLOR:red;"&gt;'&amp;lt;meta&amp;gt;&amp;lt;customergroup&amp;gt;F&amp;lt;/customergroup&amp;gt;&amp;lt;mosaic&amp;gt;Young educated man&amp;lt;/mosaic&amp;gt;&amp;lt;/meta&amp;gt;'&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;UNION&lt;/span&gt; &lt;span style="COLOR:gray;"&gt;ALL &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;SELECT  &lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;2&lt;span style="COLOR:gray;"&gt;,&lt;/span&gt; &lt;span style="COLOR:red;"&gt;'&amp;lt;meta&amp;gt;&amp;lt;age&amp;gt;24&amp;lt;/age&amp;gt;&amp;lt;/meta&amp;gt;' &lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;CREATE&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt; &lt;span style="COLOR:blue;"&gt;PRIMARY&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;XML&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;INDEX&lt;/span&gt; IX_PrimaryXML &lt;span style="COLOR:blue;"&gt;ON&lt;/span&gt; #Sample&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;MemberData&lt;span style="COLOR:gray;"&gt;) &lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;CREATE&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt; &lt;span style="COLOR:blue;"&gt;XML&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;INDEX&lt;/span&gt; IX_Element &lt;span style="COLOR:blue;"&gt;ON&lt;/span&gt; #Sample&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;MemberData&lt;span style="COLOR:gray;"&gt;) &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt; &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;USING&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;XML&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;INDEX&lt;/span&gt; IX_PrimaryXML &lt;span style="COLOR:blue;"&gt;FOR&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;PATH &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;As you see, I also created the primary XML index and a secondary XML index on the XML column. &lt;br /&gt;
Now let’s see what is stored in the important table. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;SELECT  &lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;MemberID&lt;span style="COLOR:gray;"&gt;, &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;        &lt;/span&gt;MemberData&lt;span style="COLOR:gray;"&gt;, &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;        &lt;/span&gt;MemberData&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;value&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;&lt;span style="COLOR:red;"&gt;'/meta[1]/customergroup[1]'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;,&lt;/span&gt; &lt;span style="COLOR:red;"&gt;'VARCHAR(8)'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;)&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;AS&lt;/span&gt; CustomerGroup&lt;span style="COLOR:gray;"&gt;, &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;        &lt;/span&gt;MemberData&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;value&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;&lt;span style="COLOR:red;"&gt;'/meta[1]/mosaic[1]'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;,&lt;/span&gt; &lt;span style="COLOR:red;"&gt;'VARCHAR(200)'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;)&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;AS&lt;/span&gt; Mosaic&lt;span style="COLOR:gray;"&gt;, &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;        &lt;/span&gt;MemberData&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;value&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;&lt;span style="COLOR:red;"&gt;'/meta[1]/age[1]'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;,&lt;/span&gt; &lt;span style="COLOR:red;"&gt;'TINYINT'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;)&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;AS&lt;/span&gt; Age&lt;span style="COLOR:gray;"&gt;, &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;        &lt;/span&gt;MemberData&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;value&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;&lt;span style="COLOR:red;"&gt;'/meta[1]/zipcode[1]'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;,&lt;/span&gt; &lt;span style="COLOR:red;"&gt;'VARCHAR(5)'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;)&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;AS&lt;/span&gt; ZipCode&lt;span style="COLOR:gray;"&gt;, &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;        MemberData&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;value&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;&lt;span style="COLOR:red;"&gt;'/meta[1]/status[1]'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;,&lt;/span&gt; &lt;span style="COLOR:red;"&gt;'VARCHAR(15)'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;)&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;AS&lt;/span&gt; [Status] &lt;br /&gt;
&lt;/span&gt;&lt;span style="LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-no-proof:yes;"&gt;FROM    &lt;/span&gt;&lt;span style="LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-no-proof:yes;"&gt;#Sample &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;The exercise now is to add one or more elements to the XML column, both with using a variable but also, more importantly, using a column. Create a helper table like this below. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;DECLARE &lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;@Sample &lt;span style="COLOR:blue;"&gt;TABLE &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:gray;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;        ( &lt;br /&gt;
&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:gray;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;            &lt;/span&gt;MemberID &lt;span style="COLOR:blue;"&gt;INT&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;, &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:gray;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;            &lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-no-proof:yes;"&gt;ZipCode &lt;span style="COLOR:blue;"&gt;VARCHAR&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;5&lt;span style="COLOR:gray;"&gt;), &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-no-proof:yes;"&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:gray;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;            &lt;/span&gt;&lt;/span&gt;Mosaic &lt;span style="COLOR:blue;"&gt;VARCHAR&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;200&lt;span style="COLOR:gray;"&gt;) &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-no-proof:yes;"&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:gray;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;        &lt;/span&gt;&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;) &lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-no-proof:yes;"&gt;INSERT  &lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-no-proof:yes;"&gt;@Sample &lt;br /&gt;
&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-no-proof:yes;"&gt;SELECT  &lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-no-proof:yes;"&gt;1&lt;span style="COLOR:gray;"&gt;,&lt;/span&gt; &lt;span style="COLOR:red;"&gt;'26737'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;,&lt;/span&gt; &lt;span style="COLOR:red;"&gt;'SQLTeam'&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;UNION&lt;/span&gt; &lt;span style="COLOR:gray;"&gt;ALL &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;SELECT  &lt;/span&gt;&lt;span style="LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;2&lt;span style="COLOR:gray;"&gt;,&lt;/span&gt; &lt;span style="COLOR:red;"&gt;'12345'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;,&lt;/span&gt; &lt;span style="COLOR:red;"&gt;'Smart woman in the countryside' &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;When an element doesn’t already exist, the element is added to the XML column. Beware that an additional element is created if one alerady exists! &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="FONT-FAMILY:'Courier New';COLOR:green;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;-- New element for all &lt;br /&gt;
&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;UPDATE&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="mso-tab-count:1;"&gt;      &lt;/span&gt;s &lt;br /&gt;
&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;SET&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="mso-tab-count:1;"&gt;         &lt;/span&gt;MemberData&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;modify&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;&lt;span style="COLOR:red;"&gt;'insert &amp;lt;zipcode&amp;gt;{sql:column("x.ZipCode")}&amp;lt;/zipcode&amp;gt; into (/meta)[1]'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;) &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-no-proof:yes;"&gt;FROM&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-no-proof:yes;"&gt;&lt;span style="mso-tab-count:1;"&gt;        &lt;/span&gt;#Sample &lt;span style="COLOR:blue;"&gt;AS&lt;/span&gt; s &lt;br /&gt;
&lt;/span&gt;&lt;span style="LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';COLOR:gray;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;INNER&lt;/span&gt;&lt;span style="LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt; &lt;span style="COLOR:gray;"&gt;JOIN&lt;/span&gt;&lt;span style="mso-tab-count:1;"&gt;  &lt;/span&gt;@Sample &lt;span style="COLOR:blue;"&gt;AS&lt;/span&gt; x &lt;span style="COLOR:blue;"&gt;ON&lt;/span&gt; x&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;MemberID &lt;span style="COLOR:gray;"&gt;=&lt;/span&gt; s&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;MemberID &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;Now do the SELECT again and you will see that a zipcode element was added to both records. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;SELECT  &lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;MemberID&lt;span style="COLOR:gray;"&gt;, &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;        &lt;/span&gt;MemberData&lt;span style="COLOR:gray;"&gt;, &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;        &lt;/span&gt;MemberData&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;value&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;&lt;span style="COLOR:red;"&gt;'/meta[1]/customergroup[1]'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;,&lt;/span&gt; &lt;span style="COLOR:red;"&gt;'VARCHAR(8)'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;)&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;AS&lt;/span&gt; CustomerGroup&lt;span style="COLOR:gray;"&gt;, &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;        &lt;/span&gt;MemberData&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;value&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;&lt;span style="COLOR:red;"&gt;'/meta[1]/mosaic[1]'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;,&lt;/span&gt; &lt;span style="COLOR:red;"&gt;'VARCHAR(200)'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;)&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;AS&lt;/span&gt; Mosaic&lt;span style="COLOR:gray;"&gt;, &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;        &lt;/span&gt;MemberData&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;value&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;&lt;span style="COLOR:red;"&gt;'/meta[1]/age[1]'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;,&lt;/span&gt; &lt;span style="COLOR:red;"&gt;'TINYINT'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;)&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;AS&lt;/span&gt; Age&lt;span style="COLOR:gray;"&gt;, &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;        &lt;/span&gt;MemberData&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;value&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;&lt;span style="COLOR:red;"&gt;'/meta[1]/zipcode[1]'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;,&lt;/span&gt; &lt;span style="COLOR:red;"&gt;'VARCHAR(5)'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;)&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;AS&lt;/span&gt; ZipCode&lt;span style="COLOR:gray;"&gt;, &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;        MemberData&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;value&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;&lt;span style="COLOR:red;"&gt;'/meta[1]/status[1]'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;,&lt;/span&gt; &lt;span style="COLOR:red;"&gt;'VARCHAR(15)'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;)&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;AS&lt;/span&gt; [Status] &lt;br /&gt;
&lt;/span&gt;&lt;span style="LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-no-proof:yes;"&gt;FROM    &lt;/span&gt;&lt;span style="LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-no-proof:yes;"&gt;#Sample &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;As I said before, if an element already exist a new elemtent with same name is added. This behaviour can be avoided by using a WHERE MemberData.exists clause. Do the updates first since it only touches existing records with matching elements and then do the inserts with the MemberData.exists clause. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="FONT-FAMILY:'Courier New';COLOR:green;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;-- Update existing element &lt;br /&gt;
&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;UPDATE&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="mso-tab-count:1;"&gt;      &lt;/span&gt;s &lt;br /&gt;
&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;SET&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="mso-tab-count:1;"&gt;         &lt;/span&gt;MemberData&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;modify&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;&lt;span style="COLOR:red;"&gt;'replace value of (/meta/mosaic/text())[1] with sql:column("x.Mosaic")'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;) &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;FROM&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="mso-tab-count:1;"&gt;        &lt;/span&gt;#Sample &lt;span style="COLOR:blue;"&gt;AS&lt;/span&gt; s &lt;br /&gt;
&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:gray;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;INNER&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt; &lt;span style="COLOR:gray;"&gt;JOIN&lt;/span&gt;&lt;span style="mso-tab-count:1;"&gt;  &lt;/span&gt;@Sample &lt;span style="COLOR:blue;"&gt;AS&lt;/span&gt; x &lt;span style="COLOR:blue;"&gt;ON&lt;/span&gt; x&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;MemberID &lt;span style="COLOR:gray;"&gt;=&lt;/span&gt; s&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;MemberID &lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:green;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;-- Insert new element. Beware of duplicates. &lt;br /&gt;
&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;UPDATE&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="mso-tab-count:1;"&gt;      &lt;/span&gt;s &lt;br /&gt;
&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;SET&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="mso-tab-count:1;"&gt;         &lt;/span&gt;MemberData&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;modify&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;&lt;span style="COLOR:red;"&gt;'insert &amp;lt;mosaic&amp;gt;{sql:column("x.Mosaic")}&amp;lt;/mosaic&amp;gt; into (/meta)[1]'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;) &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-no-proof:yes;"&gt;FROM&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-no-proof:yes;"&gt;&lt;span style="mso-tab-count:1;"&gt;        &lt;/span&gt;#Sample &lt;span style="COLOR:blue;"&gt;AS&lt;/span&gt; s &lt;br /&gt;
&lt;/span&gt;&lt;span style="LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';COLOR:gray;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;INNER&lt;/span&gt;&lt;span style="LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt; &lt;span style="COLOR:gray;"&gt;JOIN&lt;/span&gt;&lt;span style="mso-tab-count:1;"&gt;  &lt;/span&gt;@Sample &lt;span style="COLOR:blue;"&gt;AS&lt;/span&gt; x &lt;span style="COLOR:blue;"&gt;ON&lt;/span&gt; x&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;MemberID &lt;span style="COLOR:gray;"&gt;=&lt;/span&gt; s&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;MemberID &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;Now do the SELECT again and you will see that the element mosaic was updated for member 1 and added to member 2. This is also true for member 1 because now this member has two elements with same name. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;SELECT  &lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;MemberID&lt;span style="COLOR:gray;"&gt;, &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;        &lt;/span&gt;MemberData&lt;span style="COLOR:gray;"&gt;, &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;        &lt;/span&gt;MemberData&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;value&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;&lt;span style="COLOR:red;"&gt;'/meta[1]/customergroup[1]'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;,&lt;/span&gt; &lt;span style="COLOR:red;"&gt;'VARCHAR(8)'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;)&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;AS&lt;/span&gt; CustomerGroup&lt;span style="COLOR:gray;"&gt;, &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;        &lt;/span&gt;MemberData&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;value&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;&lt;span style="COLOR:red;"&gt;'/meta[1]/mosaic[1]'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;,&lt;/span&gt; &lt;span style="COLOR:red;"&gt;'VARCHAR(200)'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;)&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;AS&lt;/span&gt; Mosaic&lt;span style="COLOR:gray;"&gt;, &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;        &lt;/span&gt;MemberData&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;value&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;&lt;span style="COLOR:red;"&gt;'/meta[1]/age[1]'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;,&lt;/span&gt; &lt;span style="COLOR:red;"&gt;'TINYINT'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;)&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;AS&lt;/span&gt; Age&lt;span style="COLOR:gray;"&gt;, &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;        &lt;/span&gt;MemberData&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;value&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;&lt;span style="COLOR:red;"&gt;'/meta[1]/zipcode[1]'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;,&lt;/span&gt; &lt;span style="COLOR:red;"&gt;'VARCHAR(5)'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;)&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;AS&lt;/span&gt; ZipCode&lt;span style="COLOR:gray;"&gt;, &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;        MemberData&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;value&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;&lt;span style="COLOR:red;"&gt;'/meta[1]/status[1]'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;,&lt;/span&gt; &lt;span style="COLOR:red;"&gt;'VARCHAR(15)'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;)&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;AS&lt;/span&gt; [Status] &lt;br /&gt;
&lt;/span&gt;&lt;span style="LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-no-proof:yes;"&gt;FROM    &lt;/span&gt;&lt;span style="LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-no-proof:yes;"&gt;#Sample &lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;br /&gt;
&lt;/span&gt;And this was my reason for this blog post. How to add and replace elements with values from another column. So why not display how to do this with variables too? &lt;br /&gt;
&lt;br /&gt;
&lt;span style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;br /&gt;
DECLARE&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt; @Status &lt;span style="COLOR:blue;"&gt;VARCHAR&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;18&lt;span style="COLOR:gray;"&gt;) &lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;SET&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="mso-tab-count:1;"&gt;         &lt;/span&gt;@Status &lt;span style="COLOR:gray;"&gt;=&lt;/span&gt; &lt;span style="COLOR:red;"&gt;'Shipped' &lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:green;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;-- Update single record without prior element &lt;br /&gt;
&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;UPDATE&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="mso-tab-count:1;"&gt;      &lt;/span&gt;#Sample &lt;br /&gt;
&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;SET&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="mso-tab-count:1;"&gt;         &lt;/span&gt;MemberData&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;modify&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;&lt;span style="COLOR:red;"&gt;'replace value of (/meta/status/text())[1] with sql:variable("@Status")'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;) &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;WHERE&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="mso-tab-count:1;"&gt;       &lt;/span&gt;MemberID &lt;span style="COLOR:gray;"&gt;=&lt;/span&gt; 1 &lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:green;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;-- Create new element for single record &lt;br /&gt;
&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;UPDATE&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="mso-tab-count:1;"&gt;      &lt;/span&gt;#Sample &lt;br /&gt;
&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;SET&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="mso-tab-count:1;"&gt;         &lt;/span&gt;MemberData&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;modify&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;&lt;span style="COLOR:red;"&gt;'insert &amp;lt;status&amp;gt;{sql:variable("@Status")}&amp;lt;/status&amp;gt; as last into (/meta)[1]'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;)&lt;/span&gt; &lt;br /&gt;
&lt;/span&gt;&lt;span style="LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-no-proof:yes;"&gt;WHERE&lt;/span&gt;&lt;span style="LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-no-proof:yes;"&gt;&lt;span style="mso-tab-count:1;"&gt;       &lt;/span&gt;MemberID &lt;span style="COLOR:gray;"&gt;=&lt;/span&gt; 2 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;As you can see now, same rules apply. Member 1 did not get a new Status element since we wanted to update previous value. But member 2 did get a new element. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;SELECT  &lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;MemberID&lt;span style="COLOR:gray;"&gt;, &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;        &lt;/span&gt;MemberData&lt;span style="COLOR:gray;"&gt;, &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;        &lt;/span&gt;MemberData&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;value&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;&lt;span style="COLOR:red;"&gt;'/meta[1]/customergroup[1]'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;,&lt;/span&gt; &lt;span style="COLOR:red;"&gt;'VARCHAR(8)'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;)&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;AS&lt;/span&gt; CustomerGroup&lt;span style="COLOR:gray;"&gt;, &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;        &lt;/span&gt;MemberData&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;value&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;&lt;span style="COLOR:red;"&gt;'/meta[1]/mosaic[1]'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;,&lt;/span&gt; &lt;span style="COLOR:red;"&gt;'VARCHAR(200)'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;)&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;AS&lt;/span&gt; Mosaic&lt;span style="COLOR:gray;"&gt;, &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;        &lt;/span&gt;MemberData&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;value&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;&lt;span style="COLOR:red;"&gt;'/meta[1]/age[1]'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;,&lt;/span&gt; &lt;span style="COLOR:red;"&gt;'TINYINT'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;)&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;AS&lt;/span&gt; Age&lt;span style="COLOR:gray;"&gt;, &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;        &lt;/span&gt;MemberData&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;value&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;&lt;span style="COLOR:red;"&gt;'/meta[1]/zipcode[1]'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;,&lt;/span&gt; &lt;span style="COLOR:red;"&gt;'VARCHAR(5)'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;)&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;AS&lt;/span&gt; ZipCode&lt;span style="COLOR:gray;"&gt;, &lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:en-us;mso-no-proof:yes;"&gt;        MemberData&lt;span style="COLOR:gray;"&gt;.&lt;/span&gt;value&lt;span style="COLOR:gray;"&gt;(&lt;/span&gt;&lt;span style="COLOR:red;"&gt;'/meta[1]/status[1]'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;,&lt;/span&gt; &lt;span style="COLOR:red;"&gt;'VARCHAR(15)'&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;)&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;AS&lt;/span&gt; [Status] &lt;br /&gt;
&lt;/span&gt;&lt;span style="LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-no-proof:yes;"&gt;FROM    &lt;/span&gt;&lt;span style="LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-no-proof:yes;"&gt;#Sample &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;Don’t forget to do your housecleaning and drop the important table. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-no-proof:yes;"&gt;DROP&lt;/span&gt;&lt;span style="LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-no-proof:yes;"&gt; &lt;span style="COLOR:blue;"&gt;TABLE&lt;/span&gt;&lt;span style="mso-tab-count:1;"&gt;  &lt;/span&gt;#Sample &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;Besides doing update and insert, you can also use the delete syntax to remove elements if you jus don’t to clear them. &lt;br /&gt;
I hope you liked this post.&lt;/p&gt;
&lt;p&gt;Cheers! &lt;/p&gt;&lt;img src="http://weblogs.sqlteam.com/peterl/aggbug/60949.aspx" width="1" height="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=2VgS2zjekBU:l7OnYiw9NkI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=2VgS2zjekBU:l7OnYiw9NkI:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=2VgS2zjekBU:l7OnYiw9NkI:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?i=2VgS2zjekBU:l7OnYiw9NkI:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=2VgS2zjekBU:l7OnYiw9NkI:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?i=2VgS2zjekBU:l7OnYiw9NkI:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=2VgS2zjekBU:l7OnYiw9NkI:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=2VgS2zjekBU:l7OnYiw9NkI:gRsNgB-aSSA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=gRsNgB-aSSA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=2VgS2zjekBU:l7OnYiw9NkI:as7VaYKENsE"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=as7VaYKENsE" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlteamcomWeblogs/~4/2VgS2zjekBU" height="1" width="1" /&gt;</description>
      <link>http://feedproxy.google.com/~r/SqlteamcomWeblogs/~3/2VgS2zjekBU/Manipulate-XML-data-with-non-xml-columns-and-not-using-variable.aspx</link>
      <source url="http://weblogs.sqlteam.com/mainfeed2.aspx">The SQLTeam.com Weblogs</source>
      <author>Peter Larsson</author>
      <dc:creator>Peter Larsson</dc:creator>
      <comments>http://weblogs.sqlteam.com/peterl/archive/2009/07/03/Manipulate-XML-data-with-non-xml-columns-and-not-using-variable.aspx#comment</comments>
      <guid isPermaLink="False">http://weblogs.sqlteam.com/peterl/archive/2009/07/03/Manipulate-XML-data-with-non-xml-columns-and-not-using-variable.aspx</guid>
      <pubDate>Fri, 03 Jul 2009 09:57:15 GMT</pubDate>
    </item>
    <item>
      <title>Leeds Area SQL Server User Group Meeting, Leeds - Monday 20th July</title>
      <description>Managing a large SQL Server estate If size matters Martin Cairney would have the bragging rights!! Martin Cairney Martin Cairney has over 10 years experience as a SQL Server DBA. In his time he has worked for one of the largest IT services companies in the world deploying and supporting SQL Server installations from versions 6.5 through to 2005. Martin has supported some the SQL Server estate of some major Government Departments and Financial Institutions as well as a variety of occasional consultancy...(&lt;a href="http://sqlblogcasts.com/blogs/martinbell/archive/2009/07/03/leeds-area-sql-server-user-group-meeting-leeds-monday-20th-july.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=11939" width="1" height="1"&gt;</description>
      <link>http://sqlblogcasts.com/blogs/martinbell/archive/2009/07/03/leeds-area-sql-server-user-group-meeting-leeds-monday-20th-july.aspx</link>
      <source url="http://sqlblogcasts.com/blogs/">SQL Server Community Blogs</source>
      <author>MartinBell</author>
      <dc:creator>MartinBell</dc:creator>
      <guid isPermaLink="False">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:11939</guid>
      <pubDate>Fri, 03 Jul 2009 06:39:00 GMT</pubDate>
    </item>
    <item>
      <title>SQL Nuggets</title>
      <description>What are SQL Nuggets?...(&lt;a href="http://sqlblogcasts.com/blogs/martinbell/archive/2009/07/03/SQL-Nuggets.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=11938" width="1" height="1"&gt;</description>
      <link>http://sqlblogcasts.com/blogs/martinbell/archive/2009/07/03/SQL-Nuggets.aspx</link>
      <source url="http://sqlblogcasts.com/blogs/">SQL Server Community Blogs</source>
      <author>MartinBell</author>
      <dc:creator>MartinBell</dc:creator>
      <guid isPermaLink="False">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:11938</guid>
      <pubDate>Fri, 03 Jul 2009 06:15:00 GMT</pubDate>
    </item>
    <item>
      <title>WCF-SQL Adapter fails while inserting rows to a table that has an identity column.</title>
      <description>&lt;p&gt;I was working on a Biztalk integration project that perform a CRUD operation using old SQL adapter (the new one is available via Microsoft Adapter Pack 2.0), everything works fine on the development environment but when we've tried to deploy it to test environment which have the same structure with the production server we stumble again on MSDTC issues. &lt;/p&gt;
&lt;p&gt;To cut the story short it was too complicated and too many settings (firewall, NETBIOS etc) needs to be change since the database server is located on DMZ. The next day while I'm configuring the mySAP adapter, I found out that license has expired, since we've downloaded the trial version of BizTalk adapter pack 1.0. So I have to look for another setup, it so happen that for some reason I can't find the 1.0 version that's why I've installed the Adapter pack 2.0. I was a little bit surprise to see that there's a new SQL Adapter included. So I've installed it and give it a try and it works fine.&lt;/p&gt;
&lt;p&gt;Two important sql binding settings that needs to be set are:&lt;/p&gt;
&lt;p&gt;1) useAmbientTransaction = false, to solve &lt;strong&gt;MSDTC issue.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;2) allowIdentityInsert = true, if you're trying to add rows to a table that has &lt;strong&gt;identity column.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;1) &lt;img height="580" width="420" alt="" src="/images/weblogs_sqlteam_com/randyp/wcfsql.PNG" /&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;&lt;img src="http://weblogs.sqlteam.com/randyp/aggbug/60948.aspx" width="1" height="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=sNcOfpvtMnA:I5ZHHRy-r3g:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=sNcOfpvtMnA:I5ZHHRy-r3g:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=sNcOfpvtMnA:I5ZHHRy-r3g:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?i=sNcOfpvtMnA:I5ZHHRy-r3g:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=sNcOfpvtMnA:I5ZHHRy-r3g:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?i=sNcOfpvtMnA:I5ZHHRy-r3g:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=sNcOfpvtMnA:I5ZHHRy-r3g:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=sNcOfpvtMnA:I5ZHHRy-r3g:gRsNgB-aSSA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=gRsNgB-aSSA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=sNcOfpvtMnA:I5ZHHRy-r3g:as7VaYKENsE"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=as7VaYKENsE" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlteamcomWeblogs/~4/sNcOfpvtMnA" height="1" width="1" /&gt;</description>
      <link>http://feedproxy.google.com/~r/SqlteamcomWeblogs/~3/sNcOfpvtMnA/60948.aspx</link>
      <source url="http://weblogs.sqlteam.com/mainfeed2.aspx">The SQLTeam.com Weblogs</source>
      <author>Randy Aldrich Paulo</author>
      <dc:creator>Randy Aldrich Paulo</dc:creator>
      <comments>http://weblogs.sqlteam.com/randyp/archive/2009/07/03/60948.aspx#comment</comments>
      <guid isPermaLink="False">http://weblogs.sqlteam.com/randyp/archive/2009/07/03/60948.aspx</guid>
      <pubDate>Fri, 03 Jul 2009 03:58:25 GMT</pubDate>
    </item>
    <item>
      <title>Database Programming: The Time Zone Conversion Beast, Once Comatose, Returns to Taunt Us a Second Time (or, An Answer for Iain)</title>
      <description>Now go away, or we shall taunt you a second time. - John Cleese as a French knight (picture at left); Monty Python and the Holy Grail One of the reasons I started blogging over four years ago was my conviction that the coding challenges with which my...(&lt;a href="http://blogs.technet.com/wardpond/archive/2009/07/02/database-programming-the-time-zone-conversion-beast-once-comatose-returns-to-taunt-us-a-second-time-or-an-answer-for-iain.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3260937" width="1" height="1"&gt;</description>
      <link>http://blogs.technet.com/wardpond/archive/2009/07/02/database-programming-the-time-zone-conversion-beast-once-comatose-returns-to-taunt-us-a-second-time-or-an-answer-for-iain.aspx</link>
      <source url="http://blogs.technet.com/wardpond/default.aspx">Ward Pond's SQL Server blog</source>
      <author>Ward Pond</author>
      <dc:creator>Ward Pond</dc:creator>
      <comments>http://blogs.technet.com/wardpond/comments/3260937.aspx</comments>
      <guid isPermaLink="False">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3260937</guid>
      <pubDate>Thu, 02 Jul 2009 23:15:00 GMT</pubDate>
    </item>
    <item>
      <title>DRY SQL</title>
      <description>&lt;p&gt;I recently inherited some SQL that someone else had written and had the job of “tidying it up” before it gets pushed out to production. Here’s a slightly simplified (yes, simplified) version of that SQL:&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &lt;font color="#008000"&gt;--options&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt;    asset_class&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt; ,        &lt;span style="color:#0000ff;"&gt;case&lt;/span&gt;    &lt;span style="color:#0000ff;"&gt;when&lt;/span&gt; volume &amp;gt; 0 &lt;span style="color:#0000ff;"&gt;then&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;'profit'&lt;/span&gt; &lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt;                 &lt;span style="color:#0000ff;"&gt;else&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;'loss'&lt;/span&gt; &lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum5"&gt;   5:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;end&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; profit_or_loss&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum6"&gt;   6:&lt;/span&gt; ,        customer&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum7"&gt;   7:&lt;/span&gt; ,        &lt;span style="color:#0000ff;"&gt;&lt;font color="#ff00ff"&gt;sum&lt;/font&gt;&lt;/span&gt;(volume) &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; total_volume&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum8"&gt;   8:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt;    t1&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum9"&gt;   9:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;where&lt;/span&gt;    asset_class = &lt;span style="color:#ff0000;"&gt;'options'&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum10"&gt;  10:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;group&lt;/span&gt;    &lt;span style="color:#0000ff;"&gt;by&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum11"&gt;  11:&lt;/span&gt;         asset_class&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum12"&gt;  12:&lt;/span&gt; ,        &lt;span style="color:#0000ff;"&gt;case&lt;/span&gt;    &lt;span style="color:#0000ff;"&gt;when&lt;/span&gt; volume &amp;gt; 0 &lt;span style="color:#0000ff;"&gt;then&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;'profit'&lt;/span&gt; &lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum13"&gt;  13:&lt;/span&gt;                 &lt;span style="color:#0000ff;"&gt;else&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;'loss'&lt;/span&gt; &lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum14"&gt;  14:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;end&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum15"&gt;  15:&lt;/span&gt; ,        customer&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum16"&gt;  16:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;union&lt;/span&gt;    &lt;span style="color:#0000ff;"&gt;&lt;font color="#808080"&gt;all&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum17"&gt;  17:&lt;/span&gt; &lt;font color="#008000"&gt;--swaps&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum18"&gt;  18:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt;    asset_class&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum19"&gt;  19:&lt;/span&gt; ,        &lt;span style="color:#0000ff;"&gt;case&lt;/span&gt;    &lt;span style="color:#0000ff;"&gt;when&lt;/span&gt; volume &amp;gt; 0 &lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum20"&gt;  20:&lt;/span&gt;                     &lt;span style="color:#0000ff;"&gt;then&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;'profit'&lt;/span&gt; &lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum21"&gt;  21:&lt;/span&gt;                 &lt;span style="color:#0000ff;"&gt;else&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;'loss'&lt;/span&gt; &lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum22"&gt;  22:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;end&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; profit_or_loss&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum23"&gt;  23:&lt;/span&gt; ,        customer&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum24"&gt;  24:&lt;/span&gt; ,        &lt;span style="color:#0000ff;"&gt;&lt;font color="#ff00ff"&gt;sum&lt;/font&gt;&lt;/span&gt;(volume) &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; total_volume&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum25"&gt;  25:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt;    t2&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum26"&gt;  26:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;where&lt;/span&gt;    asset_class = &lt;span style="color:#ff0000;"&gt;'swaps'&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum27"&gt;  27:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;group&lt;/span&gt;    &lt;span style="color:#0000ff;"&gt;by&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum28"&gt;  28:&lt;/span&gt;         asset_class&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum29"&gt;  29:&lt;/span&gt; ,        &lt;span style="color:#0000ff;"&gt;case&lt;/span&gt;    &lt;span style="color:#0000ff;"&gt;when&lt;/span&gt; volume &amp;gt; 0 &lt;span style="color:#0000ff;"&gt;then&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;'profit'&lt;/span&gt; &lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum30"&gt;  30:&lt;/span&gt;                 &lt;span style="color:#0000ff;"&gt;else&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;'loss'&lt;/span&gt; &lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum31"&gt;  31:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;end&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum32"&gt;  32:&lt;/span&gt; ,        customer&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;The SQL basically takes data from two tables (t1 &amp;amp; t2), aggregates each, carries out some inline expressions (for &lt;font face="Lucida Console"&gt;profit_or_loss&lt;/font&gt;) and finally unions it all together. On the surface it looks fine but there are a few problems here, namely that there is a lot of repeated code; it violates the principle of &lt;a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself"&gt;don’t repeat yourself&lt;/a&gt; (DRY) which preaches “single point of maintenance” and “deduplication” of code. If you take the time to check it out you’ll see that identical aggregations are carried out on the two datasets (lines 7 &amp;amp; 24) as are the same conversions for &lt;font face="Lucida Console"&gt;profit_or_loss &lt;/font&gt;(lines 3-5 &amp;amp; 19-22). Not only that but we have expressions appearing in both the SELECT clause and GROUP BY of both halves of the query (lines 12-14 &amp;amp; 29-31), another violation of DRY.&lt;/p&gt;

&lt;p&gt;A bit of refactoring is called for. First job, eliminate those expressions for &lt;font face="Lucida Console"&gt;profit_or_loss &lt;/font&gt;which appear in the GROUP BY clauses:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &lt;font color="#008000"&gt;--options&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt;    asset_class&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt; ,        profit_or_loss&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt; ,        customer&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum5"&gt;   5:&lt;/span&gt; ,        &lt;span style="color:#0000ff;"&gt;&lt;font color="#ff00ff"&gt;sum&lt;/font&gt;&lt;/span&gt;(volume) &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; total_volume&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum6"&gt;   6:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt;    (&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum7"&gt;   7:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt;    asset_class&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum8"&gt;   8:&lt;/span&gt;         ,        customer&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum9"&gt;   9:&lt;/span&gt;         ,        &lt;span style="color:#0000ff;"&gt;case&lt;/span&gt;    &lt;span style="color:#0000ff;"&gt;when&lt;/span&gt; volume &amp;gt; 0 &lt;span style="color:#0000ff;"&gt;then&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;'profit'&lt;/span&gt; &lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum10"&gt;  10:&lt;/span&gt;                         &lt;span style="color:#0000ff;"&gt;else&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;'loss'&lt;/span&gt; &lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum11"&gt;  11:&lt;/span&gt;                 &lt;span style="color:#0000ff;"&gt;end&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; profit_or_loss&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum12"&gt;  12:&lt;/span&gt;         ,        volume&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum13"&gt;  13:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt;    t1&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum14"&gt;  14:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;where&lt;/span&gt;    asset_class = &lt;span style="color:#ff0000;"&gt;'options'&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum15"&gt;  15:&lt;/span&gt;         )t1&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum16"&gt;  16:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;group&lt;/span&gt;    &lt;span style="color:#0000ff;"&gt;by&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum17"&gt;  17:&lt;/span&gt;         asset_class&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum18"&gt;  18:&lt;/span&gt; ,        profit_or_loss&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum19"&gt;  19:&lt;/span&gt; ,        customer&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum20"&gt;  20:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;union&lt;/span&gt;    &lt;span style="color:#0000ff;"&gt;&lt;font color="#808080"&gt;all&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum21"&gt;  21:&lt;/span&gt; &lt;font color="#008000"&gt;--swaps&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum22"&gt;  22:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt;    asset_class&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum23"&gt;  23:&lt;/span&gt; ,        profit_or_loss&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum24"&gt;  24:&lt;/span&gt; ,        customer&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum25"&gt;  25:&lt;/span&gt; ,        &lt;span style="color:#0000ff;"&gt;&lt;font color="#ff00ff"&gt;sum&lt;/font&gt;&lt;/span&gt;(volume) &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; total_volume&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum26"&gt;  26:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt;    (&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum27"&gt;  27:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt;    asset_class&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum28"&gt;  28:&lt;/span&gt;         ,        customer&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum29"&gt;  29:&lt;/span&gt;         ,        &lt;span style="color:#0000ff;"&gt;case&lt;/span&gt;    &lt;span style="color:#0000ff;"&gt;when&lt;/span&gt; volume &amp;gt; 0 &lt;span style="color:#0000ff;"&gt;then&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;'profit'&lt;/span&gt; &lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum30"&gt;  30:&lt;/span&gt;                         &lt;span style="color:#0000ff;"&gt;else&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;'loss'&lt;/span&gt; &lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum31"&gt;  31:&lt;/span&gt;                 &lt;span style="color:#0000ff;"&gt;end&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; profit_or_loss&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum32"&gt;  32:&lt;/span&gt;         ,        volume&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum33"&gt;  33:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt;    t2&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum34"&gt;  34:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;where&lt;/span&gt;    asset_class = &lt;span style="color:#ff0000;"&gt;'swaps'&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum35"&gt;  35:&lt;/span&gt;         )t2&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum36"&gt;  36:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;group&lt;/span&gt;    &lt;span style="color:#0000ff;"&gt;by&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum37"&gt;  37:&lt;/span&gt;         asset_class&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum38"&gt;  38:&lt;/span&gt; ,        profit_or_loss&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum39"&gt;  39:&lt;/span&gt; ,        customer&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Ok cool, expressions have gone from our GROUP BY clauses but we’ve still got DRY violations. The aggregation (lines 5 &amp;amp; 25) and expression for &lt;font face="Lucida Console"&gt;profit_or_loss &lt;/font&gt;(lines 9-11 &amp;amp; 29-31) still appear in two places. More refactoring….&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt;    asset_class&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt; ,        customer&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt; ,        &lt;span style="color:#0000ff;"&gt;&lt;font color="#ff00ff"&gt;sum&lt;/font&gt;&lt;/span&gt;(volume) &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; total_volume&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt;    (&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum5"&gt;   5:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt;    asset_class&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum6"&gt;   6:&lt;/span&gt;         ,        &lt;span style="color:#0000ff;"&gt;case&lt;/span&gt;    &lt;span style="color:#0000ff;"&gt;when&lt;/span&gt; volume &amp;gt; 0 &lt;span style="color:#0000ff;"&gt;then&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;'profit'&lt;/span&gt; &lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum7"&gt;   7:&lt;/span&gt;                         &lt;span style="color:#0000ff;"&gt;else&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;'loss'&lt;/span&gt; &lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum8"&gt;   8:&lt;/span&gt;                 &lt;span style="color:#0000ff;"&gt;end&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; profit_or_loss&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum9"&gt;   9:&lt;/span&gt;         ,        customer&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum10"&gt;  10:&lt;/span&gt;         ,        volume&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum11"&gt;  11:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt;    (&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum12"&gt;  12:&lt;/span&gt;                 &lt;font color="#008000"&gt;--options&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum13"&gt;  13:&lt;/span&gt;                 &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt;    asset_class&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum14"&gt;  14:&lt;/span&gt;                 ,        customer&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum15"&gt;  15:&lt;/span&gt;                 ,        volume&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum16"&gt;  16:&lt;/span&gt;                 &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt;    t1&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum17"&gt;  17:&lt;/span&gt;                 &lt;span style="color:#0000ff;"&gt;where&lt;/span&gt;    asset_class = &lt;span style="color:#ff0000;"&gt;'options'&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum18"&gt;  18:&lt;/span&gt;                 &lt;span style="color:#0000ff;"&gt;union&lt;/span&gt;    &lt;span style="color:#0000ff;"&gt;&lt;font color="#808080"&gt;all&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum19"&gt;  19:&lt;/span&gt;                 &lt;font color="#008000"&gt;--swaps&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum20"&gt;  20:&lt;/span&gt;                 &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt;    asset_class&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum21"&gt;  21:&lt;/span&gt;                 ,        customer&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum22"&gt;  22:&lt;/span&gt;                 ,        volume&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum23"&gt;  23:&lt;/span&gt;                 &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt;    t2&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum24"&gt;  24:&lt;/span&gt;                 &lt;span style="color:#0000ff;"&gt;where&lt;/span&gt;    asset_class = &lt;span style="color:#ff0000;"&gt;'swaps'&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum25"&gt;  25:&lt;/span&gt;                 )t&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum26"&gt;  26:&lt;/span&gt;         )q&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum27"&gt;  27:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;group&lt;/span&gt;    &lt;span style="color:#0000ff;"&gt;by&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum28"&gt;  28:&lt;/span&gt;         asset_class&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum29"&gt;  29:&lt;/span&gt; ,        customer&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;There, much better; the aggregation only occurs once as does the expression for &lt;font face="Lucida Console"&gt;profit_or_loss&lt;/font&gt; (which in the code that I inherited occurred &lt;em&gt;four &lt;/em&gt;different times). Our SQL is DRY and its going to be a lot easier to maintain for whomever picks the code up from me.&lt;/p&gt;

&lt;p&gt;You’ll notice we’ve got 2 levels of nested subqueries (aka derived tables). I make no apologies for that - derived tables are a great mechanism for eliminating repeated code and if you take but one bit of advice away from this blog post it would be this: &lt;em&gt;&lt;strong&gt;derived tables are your friend&lt;/strong&gt;&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Would you have refactored this the same way? Maybe you might have moved the derived tables into a dedicated view. Perhaps you might even have put the derived tables into a WITH clause like so:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;with&lt;/span&gt;    t &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; (&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt;         &lt;font color="#008000"&gt;--options&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt;    asset_class&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt;         ,        customer&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum5"&gt;   5:&lt;/span&gt;         ,        volume&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum6"&gt;   6:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt;    t1&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum7"&gt;   7:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;where&lt;/span&gt;    asset_class = &lt;span style="color:#ff0000;"&gt;'options'&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum8"&gt;   8:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;union&lt;/span&gt;    &lt;span style="color:#0000ff;"&gt;&lt;font color="#808080"&gt;all&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum9"&gt;   9:&lt;/span&gt;         &lt;font color="#008000"&gt;--swaps&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum10"&gt;  10:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt;    asset_class&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum11"&gt;  11:&lt;/span&gt;         ,        customer&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum12"&gt;  12:&lt;/span&gt;         ,        volume&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum13"&gt;  13:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt;    t2&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum14"&gt;  14:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;where&lt;/span&gt;    asset_class = &lt;span style="color:#ff0000;"&gt;'swaps'&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum15"&gt;  15:&lt;/span&gt; ),&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum16"&gt;  16:&lt;/span&gt; q &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt;    (&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum17"&gt;  17:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt;    asset_class&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum18"&gt;  18:&lt;/span&gt;         ,        &lt;span style="color:#0000ff;"&gt;case&lt;/span&gt;    &lt;span style="color:#0000ff;"&gt;when&lt;/span&gt; volume &amp;gt; 0 &lt;span style="color:#0000ff;"&gt;then&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;'profit'&lt;/span&gt; &lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum19"&gt;  19:&lt;/span&gt;                         &lt;span style="color:#0000ff;"&gt;else&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;'loss'&lt;/span&gt; &lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum20"&gt;  20:&lt;/span&gt;                 &lt;span style="color:#0000ff;"&gt;end&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; profit_or_loss&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum21"&gt;  21:&lt;/span&gt;         ,        customer&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum22"&gt;  22:&lt;/span&gt;         ,        volume&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum23"&gt;  23:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt;    t&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum24"&gt;  24:&lt;/span&gt; )&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum25"&gt;  25:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt;    asset_class&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum26"&gt;  26:&lt;/span&gt; ,        customer&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum27"&gt;  27:&lt;/span&gt; ,        &lt;span style="color:#0000ff;"&gt;&lt;font color="#ff00ff"&gt;sum&lt;/font&gt;&lt;/span&gt;(volume) &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; total_volume&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum28"&gt;  28:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt;    q&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum29"&gt;  29:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;group&lt;/span&gt;    &lt;span style="color:#0000ff;"&gt;by&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum30"&gt;  30:&lt;/span&gt;         asset_class&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;font size="4"&gt;&lt;font face="Lucida Console"&gt;&lt;span style="color:#606060;" id="lnum31"&gt;  31:&lt;/span&gt; ,        customer&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Let me know in the comments!&lt;/p&gt;

&lt;p&gt;&lt;a href="http://twitter.com/jamiet"&gt;@Jamiet&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.conchango.com/aggbug.aspx?PostID=15667" width="1" height="1"&gt;</description>
      <link>http://blogs.conchango.com/jamiethomson/archive/2009/07/02/dry-sql.aspx</link>
      <source url="http://blogs.conchango.com/jamiethomson/archive/tags/SQL+Server/default.aspx">SSIS Junkie : SQL Server</source>
      <author>jamie.thomson</author>
      <dc:creator>jamie.thomson</dc:creator>
      <comments>http://blogs.conchango.com/jamiethomson/comments/15667.aspx</comments>
      <guid isPermaLink="False">e847c0e7-38d9-45c0-b593-56747303e088:15667</guid>
      <pubDate>Thu, 02 Jul 2009 17:05:00 GMT</pubDate>
    </item>
    <item>
      <title>The next SQLbits</title>
      <description>&lt;br /&gt;
&lt;p&gt;We&amp;#39;ll be announcing the date and venue for the next 
SQLBits on Monday&lt;/p&gt;
&lt;p&gt;So keep posted, we&amp;#39;ve got some really exciting news.&lt;/p&gt;
&lt;p&gt;I am really excited about the whole event. Its going to be bigger and better 
than the others.&lt;/p&gt;
&lt;br /&gt;&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=11937" width="1" height="1"&gt;</description>
      <link>http://sqlblogcasts.com/blogs/sqlbits/archive/2009/07/02/The-next-SQLbits.aspx</link>
      <source url="http://sqlblogcasts.com/blogs/">SQL Server Community Blogs</source>
      <author>simonsabin</author>
      <dc:creator>simonsabin</dc:creator>
      <guid isPermaLink="False">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:11937</guid>
      <pubDate>Wed, 01 Jul 2009 20:43:08 GMT</pubDate>
    </item>
    <item>
      <title>The Best Thing I Learned At PASS</title>
      <description>&lt;p&gt;&lt;em&gt;Note: I'm writing this as part of the &amp;quot;Best Thing I Learned At PASS&amp;quot; &lt;/em&gt;&lt;a href="http://summit2009.sqlpass.org/AboutSummit/News/BestThingContest.aspx" target="_blank"&gt;&lt;em&gt;contest&lt;/em&gt;&lt;/a&gt;&lt;em&gt;. Why? Because if I win it's worth a free registration or hotel stay for the &lt;a href="http://summit2009.sqlpass.org/" target="_blank"&gt;2009 Summit&lt;/a&gt;, and I like free!&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Let me start by making a small confession: I've never actually been to the PASS summit in person. So how in the world can I write about what I've learned? Because I've been there vicariously through the blogs and Twitter streams of people who were there last year. Thank goodness, because before the rise of blogging\social networking if you had asked me what happens at the PASS summit I would have said…I honestly don’t know what happens at PASS besides a bunch of technical presentations given by people who write books and magazine articles for a living. My ignorance about what PASS is became clear to me last November as I read about the daily keynotes, the community sessions, and the nighttime parties. I came to realize that PASS is about so much more than just sitting in technical presentations. It’s about learning from people just like you who are doing the same things as you do every day. It’s about uniting with your peers and meeting new people who share a common interest. It’s about escaping the daily workload to reenergize and reinvigorate the passion to do our jobs as best as we possibly can when we return. So even though I haven’t been to PASS in person, I’ve learned one important thing: &lt;b&gt;For the sake of my career, I need to go to PASS&lt;/b&gt;. If I can figure that out without actually having been to PASS, just imagine what I’ll learn when I do go this year.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2173119910600284569-3801181006975092798?l=kendalvandyke.blogspot.com' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/KendalVanDyke?a=FpBsCZRLKRw:9o9NxkrierU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/KendalVanDyke?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/KendalVanDyke?a=FpBsCZRLKRw:9o9NxkrierU:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/KendalVanDyke?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/KendalVanDyke?a=FpBsCZRLKRw:9o9NxkrierU:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/KendalVanDyke?i=FpBsCZRLKRw:9o9NxkrierU:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/KendalVanDyke?a=FpBsCZRLKRw:9o9NxkrierU:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/KendalVanDyke?i=FpBsCZRLKRw:9o9NxkrierU:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/KendalVanDyke?a=FpBsCZRLKRw:9o9NxkrierU:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/KendalVanDyke?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/KendalVanDyke?a=FpBsCZRLKRw:9o9NxkrierU:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/KendalVanDyke?i=FpBsCZRLKRw:9o9NxkrierU:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/KendalVanDyke/~4/FpBsCZRLKRw" height="1" width="1" /&gt;</description>
      <link>http://kendalvandyke.blogspot.com/2009/07/best-thing-i-learned-at-pass.html</link>
      <source url="http://kendalvandyke.blogspot.com/">Kendal Van Dyke</source>
      <author>noreply@blogger.com (Kendal Van Dyke)</author>
      <dc:creator>noreply@blogger.com (Kendal Van Dyke)</dc:creator>
      <guid isPermaLink="False">tag:blogger.com,1999:blog-2173119910600284569.post-3801181006975092798</guid>
      <pubDate>Wed, 01 Jul 2009 19:00:00 GMT</pubDate>
    </item>
    <item>
      <title>ROW Constructors are dead, long live Table Value Constructors!</title>
      <description>New documentation on ROW CONSTRUCTORS indicate the feature has had a name change to Table Value Constructors...(&lt;a href="http://sqlblogcasts.com/blogs/martinbell/archive/2009/07/01/ROW-CONSTRUCTORS-are-dead_2C00_-long-live-Table-Value-Constructors_2100_.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=11934" width="1" height="1"&gt;</description>
      <link>http://sqlblogcasts.com/blogs/martinbell/archive/2009/07/01/ROW-CONSTRUCTORS-are-dead_2C00_-long-live-Table-Value-Constructors_2100_.aspx</link>
      <source url="http://sqlblogcasts.com/blogs/">SQL Server Community Blogs</source>
      <author>MartinBell</author>
      <dc:creator>MartinBell</dc:creator>
      <guid isPermaLink="False">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:11934</guid>
      <pubDate>Wed, 01 Jul 2009 17:48:00 GMT</pubDate>
    </item>
    <item>
      <title>When in doubt, Reboot!</title>
      <description>&lt;p&gt;I tend to get quite a bit of Kerberos related cases.&amp;#160; These are related across the box, from the Engine, to Reporting Services to just straight connectivity with custom applications.&amp;#160; I had one given to me yesterday because the engineer had gone through everything we normally go through and wasn’t getting anywhere.&lt;/p&gt;  &lt;p&gt;The situation was an 8 node cluster with multiple instances across the nodes.&amp;#160; These were running Windows 2008 with SQL 2008.&amp;#160; One node in particular was having an issue when they were issuing a Linked Server Query from a remote client.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/psssql/WindowsLiveWriter/WhenindoubtReboot_E3D4/image_4.png"&gt;&lt;img title="image" style="border-right:0px;border-top:0px;display:inline;border-left:0px;border-bottom:0px;" height="331" alt="image" src="http://blogs.msdn.com/blogfiles/psssql/WindowsLiveWriter/WhenindoubtReboot_E3D4/image_thumb_1.png" width="514" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;When trying to hit the linked server from within Management Studio on the client machine, we received the following message:&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New" size="2"&gt;Msg 18456, Level 14, State 1, Line 1     &lt;br /&gt;Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'&lt;/font&gt;&lt;/p&gt;  &lt;h4&gt;Kerberos Configuration:&lt;/h4&gt;  &lt;p&gt;When we see this type of error, it is typically Kerberos related as the Service we are using (ServerA) is unable to delegate the client’s credentials to the backend server (ServerB – Linked Server).&amp;#160; The first thing we do is go through our regular kerberos checklist – SPN’s and Delegation settings. Both SQL Servers were using the same Domain User Service Account (SNEAKERNET\SQLSvc).&amp;#160; We can use SetSPN to check what SPN’s are on that account.&amp;#160; NOTE:&amp;#160; There are numerous ways to look for SPN’s but SetSPN is one of the easier command line tools available.&amp;#160; You could also use LDIFDE (&lt;a title="http://support.microsoft.com/kb/237677" href="http://support.microsoft.com/kb/237677"&gt;http://support.microsoft.com/kb/237677&lt;/a&gt;), ADSIEdit (&lt;a title="http://technet.microsoft.com/en-us/library/cc773354(WS.10).aspx" href="http://technet.microsoft.com/en-us/library/cc773354(WS.10).aspx"&gt;http://technet.microsoft.com/en-us/library/cc773354(WS.10).aspx&lt;/a&gt;) and other tools.&amp;#160; You will see us use an in house tool called DHDiag to collect SPN’s.&amp;#160; This is just a wrapper that calls LDIFDE to output the results.&amp;#160; &lt;/p&gt;  &lt;p&gt;So, here are the SetSPN results:&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New" size="2"&gt;C:\Users\Administrator&amp;gt;setspn -l sqlsvc     &lt;br /&gt;Registered ServicePrincipalNames for CN=SQL Service,OU=Service Account,DC=sneakernet,DC=local:      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; MSSQLSvc/SQL02:26445      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; MSSQLSvc/SQL02.sneakernet.local:26445      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; MSSQLSvc/SQL01.sneakernet.local:14556      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; MSSQLSvc/SQL01:14556&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Why do we see SQL01 and SQL02 when our machine names are ServerA and ServerB?&amp;#160; This is because SQL01 and SQL02 are the virtual names for the cluster.&amp;#160; This name will move to whatever the active node is for that given instance.&amp;#160; Where as ServerA and ServerB are the physical machine names and may or may not be actually hosting that instance.&amp;#160; We can also see from this that we have two distinct instances because of the ports (14556 &amp;amp; 26445).&amp;#160; If you look at some of our documentation (i.e. &lt;a title="http://msdn.microsoft.com/en-us/library/ms189585(SQL.90).aspx" href="http://msdn.microsoft.com/en-us/library/ms189585(SQL.90).aspx"&gt;http://msdn.microsoft.com/en-us/library/ms189585(SQL.90).aspx&lt;/a&gt;), it indicates that for clusters, you need to also add a SQL SPN that does not include the port number.&amp;#160; I have yet to see where this is actually needed.&amp;#160; Every cluster I’ve seen has never had one.&amp;#160; Typically if it is needed, you will receive a KRB_ERR_S_PRINCIPAL_UNKNOWN error if you enable Kerberos Event Logging.&amp;#160; If you do see that and it lists that SPN, then go ahead and add it.&amp;#160; But, from my experience, you won’t see it.&lt;/p&gt;  &lt;p&gt;Ok, our SPNs look good. Lets look at our Delegation Settings.&amp;#160; In this case we really care about the SQL Service Account, because that is the context that will be performing the delegation.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/psssql/WindowsLiveWriter/WhenindoubtReboot_E3D4/image_8.png"&gt;&lt;img title="image" style="border-right:0px;border-top:0px;display:inline;border-left:0px;border-bottom:0px;" height="378" alt="image" src="http://blogs.msdn.com/blogfiles/psssql/WindowsLiveWriter/WhenindoubtReboot_E3D4/image_thumb_3.png" width="538" border="0" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;We can do this by going to the properties for that account within Active Directory Users and Computers.&amp;#160; You will see a Delegation tab on the account.&amp;#160; If you don’t see the delegation tab, then the account does not have an SPN attached to it.&amp;#160; In this case we have “Trust this user for delegation to any service (Kerberos only)”.&amp;#160; This is what I call Full or Open Delegation as opposed to Constrained Delegation (which is more secure).&amp;#160; We are good to go here.&amp;#160; Nine times out of ten, the SPN or Delegation setting is going to be the cause of your issue.&amp;#160; In this case it isn’t.&amp;#160; What can we do now?&lt;/p&gt;  &lt;h4&gt;Kerberos Event Logging and Network Traces:&lt;/h4&gt;  &lt;p&gt;We can enable Kerberos Event Logging (&lt;a title="http://support.microsoft.com/default.aspx?scid=kb;EN-US;262177" href="http://support.microsoft.com/default.aspx?scid=kb;EN-US;262177"&gt;http://support.microsoft.com/default.aspx?scid=kb;EN-US;262177&lt;/a&gt;) which will give us errors within the System Log for Kerberos.&amp;#160; This can sometimes be very helpful in diagnosing what may or may not be happening.&amp;#160; This produced the following results on ServerA:&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New" size="2"&gt;Error Code: 0x1b Unknown Error     &lt;br /&gt;Error Code: 0x19 KDC_ERR_PREAUTH_REQUIRED      &lt;br /&gt;And KDC_ERR_BADOPTION&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;These are not uncommon and when we looked at these, they didn’t really relate to our issue.&amp;#160; Which means we had nothing here.&amp;#160; Of note, doing a linked server query from ServerB to ServerA worked, and it also produced the same events listed above.&amp;#160; So, nothing to gain here.&lt;/p&gt;  &lt;p&gt;The next thing we can look at is getting a network trace as this will show us the communication between Service in question and the Domain Controller.&amp;#160; I usually end up at this level if the SPN’s and Delegation settings check out.&amp;#160; This is really where some customers can have issues, because typically these are hard to interpret and will require a call to CSS.&amp;#160; We grabbed a trace in the failing and working condition to see what was different.&amp;#160; We saw the following:&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New" size="2"&gt;Failing:     &lt;br /&gt;525355 2009-06-30 15:55:39.468865 10.0.0.90 10.0.0.10 KRB5 TGS-REQ      &lt;br /&gt;KDC_REQ_BODY      &lt;br /&gt;KDCOptions: 40810000 (Forwardable, Renewable, Canonicalize)      &lt;br /&gt;Realm: SNEAKERNET.LOCAL      &lt;br /&gt;Server Name (Enterprise Name): &lt;font color="#ff0000"&gt;&lt;strong&gt;ServerA$@SNEAKERNET.LOCAL&lt;/strong&gt;&lt;/font&gt; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New" size="2"&gt;Working:     &lt;br /&gt;353115 23.437037 10.0.0.20 10.0.0.11 KRB5 TGS-REQ      &lt;br /&gt;KDC_REQ_BODY      &lt;br /&gt;KDCOptions: 40810000 (Forwardable, Renewable, Canonicalize)      &lt;br /&gt;Realm: SNEAKERNET.LOCAL      &lt;br /&gt;Server Name (Service and Instance): &lt;strong&gt;&lt;font color="#ff0000"&gt;MSSQLSvc/SQL02.sneakernet.local:26445&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;You’ll notice that we are hitting different DC’s here, but that wasn’t the issue as we also saw the failing one hitting different DC’s as we continued.&amp;#160; The other item that is different is the working one requested the right SPN, where as the failing one is requesting the physical machine account context.&amp;#160; This is what was forcing us into NTLM and causing the Login failed error.&amp;#160; But why was that happening?&amp;#160; So far we have zero information to indicate what could be causing it.&lt;/p&gt;  &lt;h4&gt;SSPIClient:&lt;/h4&gt;  &lt;p&gt;We then used an internal tool called SSPIClient which makes direct calls to the InitializeSecurityContext API call which is how we do impersonation.&amp;#160; This tool allowed us to take SQL Server out of the picture and focus on the Kerberos issue directly.&amp;#160; We could see that we were failing back to NTLM which really confirmed what we saw in the network trace.&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New" size="2"&gt;2009-07-01 16:34:24.577 ENTER InitializeSecurityContextA     &lt;br /&gt;2009-07-01 16:34:24.577 phCredential&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; = 0x0090936c      &lt;br /&gt;2009-07-01 16:34:24.577 phContext&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; = 0x00000000      &lt;br /&gt;2009-07-01 16:34:24.577 pszTargetName&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; = 'MSSQLSvc/SQL02.sneakernet.local:26445'      &lt;br /&gt;2009-07-01 16:34:24.577 fContextReq&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; = 0x00000003 ISC_REQ_DELEGATE|ISC_REQ_MUTUAL_AUTH      &lt;br /&gt;2009-07-01 16:34:24.577 TargetDataRep&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; = 16      &lt;br /&gt;2009-07-01 16:34:24.577 pInput&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; = 0x00000000      &lt;br /&gt;2009-07-01 16:34:24.577 phNewContext&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; = 0x0090937c      &lt;br /&gt;2009-07-01 16:34:24.577 pOutput&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; = 0x0017d468      &lt;br /&gt;2009-07-01 16:34:24.577 pOutput-&amp;gt;ulVersion&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; = 0      &lt;br /&gt;2009-07-01 16:34:24.577 pOutput-&amp;gt;cBuffers&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; = 1      &lt;br /&gt;2009-07-01 16:34:24.577 pBuffers[00].cbBuffer&amp;#160;&amp;#160; = 52      &lt;br /&gt;2009-07-01 16:34:24.577 pBuffers[00].BufferType = 2 SECBUFFER_TOKEN      &lt;br /&gt;2009-07-01 16:34:24.577 pBuffers[00].pvBuffer&amp;#160;&amp;#160; = 0x02c99f90      &lt;br /&gt;2009-07-01 16:34:24.578 02c99f90&amp;#160; 4e 54 4c 4d 53 53 50 00 01 00 00 00 97 b2 08 e2&amp;#160;&amp;#160; &lt;strong&gt;&lt;font color="#ff0000"&gt;NTLMSSP&lt;/font&gt;&lt;/strong&gt;.........      &lt;br /&gt;2009-07-01 16:34:24.578 02c99fa0&amp;#160; 03 00 03 00 31 00 00 00 09 00 09 00 28 00 00 00&amp;#160;&amp;#160; ....1.......(...&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;2009-07-01 16:34:24.578 pfContextAttr&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; = 0x00001000 ISC_RET_INTERMEDIATE_RETURN      &lt;br /&gt;2009-07-01 16:34:24.578 ptsExpiry&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; = &lt;strong&gt;&lt;font color="#ff0000"&gt;0x0017d43c -&amp;gt; 2009-07-01 10:39:24 *** EXPIRED *** (05:55:00 diff)&lt;/font&gt;&lt;/strong&gt;      &lt;br /&gt;2009-07-01 16:34:24.578 EXIT&amp;#160; InitializeSecurityContextA returned 0x00090312 SEC_I_CONTINUE_NEEDED (The function completed successfully, but must be called again to complete the context)&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;NOTE:&amp;#160; We purged all of the Kerberos Tickets before we did this to make sure we would request the ticket from the KDC.&amp;#160; This was done using KerbTray which is part of the Windows Resource Kit.&lt;/p&gt;  &lt;p&gt;This tells us that we were requesting a given SPN for the Target, but the buffer shows NTLMSSP.&amp;#160; This means we fell down to NTLM instead of getting Kerberos.&amp;#160; This still doesn’t explain why.&lt;/p&gt;  &lt;h4&gt;End Result:&lt;/h4&gt;  &lt;p&gt;Unfortunately, this was one of those issues that just escaped us.&amp;#160; This tends to happen with odd Kerberos cases.&amp;#160; We had the Directory Services team engaged as well and they did not know what else we could do in terms of data collection outside of a Kernel Dump to see what may be going on.&amp;#160; We noticed that the nodes had not been rebooted since April 5th which is a while.&amp;#160; The SQL Service was recycled on June 25th.&amp;#160; We decided to fail over to another node and reboot ServerA. After we rebooted, we tried SSPIClient again and we saw a proper response come back which also didn’t list EXPIRED.&amp;#160; The issue at this point it was resolved.&amp;#160; We don’t have hard data to indicate what exactly the issue was, but the thought is that something was cached and invalid causing the issue.&amp;#160; Rebooting cleared that out and allowed us to work as expected.&lt;/p&gt;  &lt;p&gt;Which leads me to my motto:&amp;#160; When in doubt, Reboot!&lt;/p&gt;  &lt;p&gt;&lt;font color="#808080"&gt;Adam W. Saxton | Microsoft SQL Server Escalation Services&lt;/font&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9811943" width="1" height="1"&gt;</description>
      <link>http://blogs.msdn.com/psssql/archive/2009/07/01/when-in-doubt-reboot.aspx</link>
      <source url="http://blogs.msdn.com/psssql/default.aspx">CSS SQL Server Engineers</source>
      <author>psssql</author>
      <dc:creator>psssql</dc:creator>
      <comments>http://blogs.msdn.com/psssql/comments/9811943.aspx</comments>
      <guid isPermaLink="False">91d46819-8472-40ad-a661-2c78acb4018c:9811943</guid>
      <pubDate>Wed, 01 Jul 2009 17:12:13 GMT</pubDate>
    </item>
    <item>
      <title>Microsoft MVP</title>
      <description>&lt;p&gt;Today it happened. I received the Microsoft &lt;a href="https://mvp.support.microsoft.com/profile=B4908039-EBFB-4531-8793-0683AAE4419D" target="_blank"&gt;MVP&lt;/a&gt; Award for my contributions to the Microsoft SQL Server community.    &lt;br /&gt;I am very honored by the award and I will continue to work hard for the community to keep their trust in me.    &lt;br /&gt;    &lt;br /&gt;I will continue to update this blog and help users out in the SQLTeam &lt;a href="http://www.sqlteam.com/forums/" target="_blank"&gt;forums&lt;/a&gt;, SqlServerCentral &lt;a href="http://www.sqlservercentral.com/Forums/" target="_blank"&gt;forums&lt;/a&gt;, SQL Server Magazine &lt;a href="http://sqlforums.windowsitpro.com/web/forum/default.aspx?forumid=10" target="_blank"&gt;forums&lt;/a&gt; and SQL Server Developer Center &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/transactsql/threads/" target="_blank"&gt;forums&lt;/a&gt; among a few other.    &lt;br /&gt;    &lt;br /&gt;Thank you to everyone who reads this blog and leave comments. I still learn something new every day.    &lt;br /&gt;    &lt;br /&gt;    &lt;br /&gt;Best Regards,    &lt;br /&gt;Peter Larsson&lt;/p&gt;&lt;img src="http://weblogs.sqlteam.com/peterl/aggbug/60946.aspx" width="1" height="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=wS5s1-o_BcI:GLFiO6kbrws:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=wS5s1-o_BcI:GLFiO6kbrws:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=wS5s1-o_BcI:GLFiO6kbrws:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?i=wS5s1-o_BcI:GLFiO6kbrws:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=wS5s1-o_BcI:GLFiO6kbrws:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?i=wS5s1-o_BcI:GLFiO6kbrws:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=wS5s1-o_BcI:GLFiO6kbrws:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=wS5s1-o_BcI:GLFiO6kbrws:gRsNgB-aSSA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=gRsNgB-aSSA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=wS5s1-o_BcI:GLFiO6kbrws:as7VaYKENsE"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=as7VaYKENsE" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlteamcomWeblogs/~4/wS5s1-o_BcI" height="1" width="1" /&gt;</description>
      <link>http://feedproxy.google.com/~r/SqlteamcomWeblogs/~3/wS5s1-o_BcI/Microsoft-MVP.aspx</link>
      <source url="http://weblogs.sqlteam.com/mainfeed2.aspx">The SQLTeam.com Weblogs</source>
      <author>Peter Larsson</author>
      <dc:creator>Peter Larsson</dc:creator>
      <comments>http://weblogs.sqlteam.com/peterl/archive/2009/07/01/Microsoft-MVP.aspx#comment</comments>
      <guid isPermaLink="False">http://weblogs.sqlteam.com/peterl/archive/2009/07/01/Microsoft-MVP.aspx</guid>
      <pubDate>Wed, 01 Jul 2009 12:33:00 GMT</pubDate>
    </item>
    <item>
      <title>July Vacation</title>
      <description>&lt;p&gt;
&lt;font face="verdana,geneva" size="2"&gt;Well - the first half of the year is over and it's been a pretty busy time for Kimberly and I. I only managed to get one day at home in June but I'm at home for whole month of July, and this year I'm taking a proper break. I'm going to be essentially dark through July - no blogging, no Twitter, no forums or newsgroups - so don't expect to hear from me until August.&lt;/font&gt; &lt;/p&gt;
&lt;p&gt;
&lt;font face="verdana,geneva" size="2"&gt;Hope you have a great summer, and Happy July 4th for those in the US.&lt;/font&gt; &lt;/p&gt;
&lt;p&gt;
&lt;font face="verdana,geneva" size="2"&gt;Cheers&lt;/font&gt; &lt;/p&gt;</description>
      <link>http://www.sqlskills.com/BLOGS/PAUL/post/July-Vacation.aspx</link>
      <source url="http://pipes.yahoo.com/pipes/pipe.info?_id=85142a7c17be56670fbddefa43f25c8d">SQLskills.com Aggregated Feed</source>
      <author>paul.nospam@nospam.sqlskills.com (paul)</author>
      <dc:creator>paul.nospam@nospam.sqlskills.com (paul)</dc:creator>
      <guid isPermaLink="False">http://www.sqlskills.com/BLOGS/PAUL/post.aspx?id=5283fda1-2a74-49d0-ae6f-fef4c6b5d239</guid>
      <pubDate>Wed, 01 Jul 2009 11:12:00 GMT</pubDate>
    </item>
    <item>
      <title>Looking for security vulnerabilities in database code</title>
      <description>&lt;p&gt;
I've always been concerned with security and I've always stressed the importance of auditing the REAL user context not just the current user (see &lt;a rel="nofollow" target="_blank" href="http://www.sqlskills.com/BLOGS/KIMBERLY/post/EXECUTE-AS-and-an-important-update-your-DDL-Triggers-(for-auditing-or-prevention).aspx"&gt;this post&lt;/a&gt; on EXECUTE AS and auditing). So, I generally try to avoid using dynamic string execution and if necessary create well tested/protected parameters (fyi - using QUOTENAME can be a fantasic solution to protectng identifiers as input parameters but it can't protect more complex strings). &lt;/p&gt;
&lt;p&gt;
Having said that, what if I'm looking at a database for the first time... just poking around trying to see if there's anything that needs further attention? I've come up with a quick query... And, while it's not going to "solve" your problem (as that's going to take some re-writing of code) or even &lt;em&gt;truly &lt;/em&gt;verify if you're vulnerable, it gives you a "quick list"&amp;nbsp;of where you should look first! If&amp;nbsp;your code uses dynamic strings AND it's elevated - then&amp;nbsp;start there!&amp;nbsp; &lt;/p&gt;
&lt;font size="5" color="#0000ff"&gt;&lt;font size="5" color="#0000ff"&gt;
&lt;blockquote&gt; &lt;p&gt; &lt;font size="2"&gt;SELECT &lt;font color="#ff00ff"&gt;&lt;font color="#ff00ff"&gt;OBJECT_NAME&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080"&gt;&lt;font color="#808080"&gt;(&lt;/font&gt;&lt;/font&gt;&lt;font color="#ff00ff"&gt;&lt;font color="#ff00ff"&gt;object_id&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080"&gt;&lt;font color="#808080"&gt;)&lt;/font&gt;&lt;/font&gt; &lt;font color="#0000ff"&gt;&lt;font color="#0000ff"&gt;AS&lt;/font&gt;&lt;/font&gt; [Procedure Name]&lt;/font&gt;&lt;font color="#808080"&gt;&lt;font size="2" color="#808080"&gt;,&lt;br /&gt; &lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;&lt;font color="#0000ff"&gt;&amp;nbsp; CASE&lt;br /&gt; &lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; WHEN&lt;/font&gt;&lt;/font&gt; sm&lt;font color="#808080"&gt;&lt;font color="#808080"&gt;.&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&lt;font color="#0000ff"&gt;definition&lt;/font&gt;&lt;/font&gt; &lt;font color="#808080"&gt;&lt;font color="#808080"&gt;LIKE&lt;/font&gt;&lt;/font&gt; &lt;font color="#ff0000"&gt;&lt;font color="#ff0000"&gt;'%EXEC (%'&lt;/font&gt;&lt;/font&gt; &lt;font color="#808080"&gt;&lt;font color="#808080"&gt;OR&lt;/font&gt;&lt;/font&gt; sm&lt;font color="#808080"&gt;&lt;font color="#808080"&gt;.&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&lt;font color="#0000ff"&gt;definition&lt;/font&gt;&lt;/font&gt; &lt;font color="#808080"&gt;&lt;font color="#808080"&gt;LIKE&lt;/font&gt;&lt;/font&gt; &lt;font color="#ff0000"&gt;&lt;font color="#ff0000"&gt;'%EXEC(%'&lt;/font&gt;&lt;/font&gt; &lt;font color="#0000ff"&gt;&lt;font color="#0000ff"&gt;THEN&lt;/font&gt;&lt;/font&gt; &lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#ff0000"&gt;&lt;font color="#ff0000"&gt;'WARNING: code contains EXEC'&lt;br /&gt; &lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHEN&lt;/font&gt;&lt;/font&gt; sm&lt;font color="#808080"&gt;&lt;font color="#808080"&gt;.&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&lt;font color="#0000ff"&gt;definition&lt;/font&gt;&lt;/font&gt; &lt;font color="#808080"&gt;&lt;font color="#808080"&gt;LIKE&lt;/font&gt;&lt;/font&gt; &lt;font color="#ff0000"&gt;&lt;font color="#ff0000"&gt;'%EXECUTE (%'&lt;/font&gt;&lt;/font&gt; &lt;font color="#808080"&gt;&lt;font color="#808080"&gt;OR&lt;/font&gt;&lt;/font&gt; sm&lt;font color="#808080"&gt;&lt;font color="#808080"&gt;.&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&lt;font color="#0000ff"&gt;definition&lt;/font&gt;&lt;/font&gt; &lt;font color="#808080"&gt;&lt;font color="#808080"&gt;LIKE&lt;/font&gt;&lt;/font&gt; &lt;font color="#ff0000"&gt;&lt;font color="#ff0000"&gt;'%EXECUTE(%'&lt;/font&gt;&lt;/font&gt; &lt;font color="#0000ff"&gt;&lt;font color="#0000ff"&gt;THEN&lt;/font&gt;&lt;/font&gt; &lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#ff0000"&gt;&lt;font color="#ff0000"&gt;'WARNING: code contains EXECUTE'&lt;br /&gt; &lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&lt;font color="#0000ff"&gt;&amp;nbsp; END&lt;/font&gt;&lt;/font&gt; &lt;font color="#0000ff"&gt;&lt;font color="#0000ff"&gt;AS&lt;/font&gt;&lt;/font&gt; [Dynamic Strings]&lt;/font&gt;&lt;font color="#808080"&gt;&lt;font size="2" color="#808080"&gt;,&lt;br /&gt; &lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;&lt;font color="#0000ff"&gt;&amp;nbsp; CASE&lt;br /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&lt;font color="#0000ff"&gt;WHEN&lt;/font&gt;&lt;/font&gt; execute_as_principal_id &lt;font color="#808080"&gt;&lt;font color="#808080"&gt;IS&lt;/font&gt;&lt;/font&gt; &lt;font color="#808080"&gt;&lt;font color="#808080"&gt;NOT&lt;/font&gt;&lt;/font&gt; &lt;font color="#808080"&gt;&lt;font color="#808080"&gt;NULL&lt;/font&gt;&lt;/font&gt; &lt;font color="#0000ff"&gt;&lt;font color="#0000ff"&gt;THEN&lt;/font&gt;&lt;/font&gt; &lt;font color="#ff0000"&gt;&lt;font color="#ff0000"&gt;N'WARNING: EXECUTE AS '&lt;/font&gt;&lt;/font&gt; &lt;font color="#808080"&gt;&lt;font color="#808080"&gt;+&lt;/font&gt;&lt;/font&gt; &lt;font color="#ff00ff"&gt;&lt;font color="#ff00ff"&gt;user_name&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080"&gt;&lt;font color="#808080"&gt;(&lt;/font&gt;&lt;/font&gt;execute_as_principal_id&lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#808080"&gt;&lt;font color="#808080"&gt;)&lt;br /&gt; &lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ELSE&lt;/font&gt;&lt;/font&gt; &lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#ff0000"&gt;&lt;font color="#ff0000"&gt;'Code to run as caller - check connection context'&lt;br /&gt; &lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&lt;font color="#0000ff"&gt;&amp;nbsp; END&lt;/font&gt;&lt;/font&gt; &lt;font color="#0000ff"&gt;&lt;font color="#0000ff"&gt;AS&lt;/font&gt;&lt;/font&gt; [Execution Context Status]&lt;br /&gt; &lt;font color="#0000ff"&gt;&lt;font color="#0000ff"&gt;FROM&lt;/font&gt;&lt;/font&gt; &lt;font color="#008000"&gt;&lt;font color="#008000"&gt;sys&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080"&gt;&lt;font color="#808080"&gt;.&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000"&gt;&lt;font color="#008000"&gt;sql_modules&lt;/font&gt;&lt;/font&gt; &lt;font color="#0000ff"&gt;&lt;font color="#0000ff"&gt;AS&lt;/font&gt;&lt;/font&gt; sm&lt;br /&gt; &lt;font color="#0000ff"&gt;&lt;font color="#0000ff"&gt;ORDER&lt;/font&gt;&lt;/font&gt; &lt;font color="#0000ff"&gt;&lt;font color="#0000ff"&gt;BY&lt;/font&gt;&lt;/font&gt; [Procedure Name] &lt;/font&gt; &lt;/p&gt;
&lt;/blockquote&gt;
&lt;/font&gt;&lt;/font&gt;
&lt;p&gt;
Is this enough? Anything else you'd check? What do you think? &lt;/p&gt;
&lt;p&gt;
THANKS!&lt;br /&gt;
kt &lt;/p&gt;</description>
      <link>http://www.sqlskills.com/BLOGS/KIMBERLY/post/Looking-for-security-vulnerabilities-in-database-code.aspx</link>
      <source url="http://pipes.yahoo.com/pipes/pipe.info?_id=85142a7c17be56670fbddefa43f25c8d">SQLskills.com Aggregated Feed</source>
      <author>kimberly.nospam@nospam.sqlskills.com (kltripp)</author>
      <dc:creator>kimberly.nospam@nospam.sqlskills.com (kltripp)</dc:creator>
      <guid isPermaLink="False">http://www.sqlskills.com/BLOGS/KIMBERLY/post.aspx?id=2a2a7de6-c0d5-4b2f-856b-f4df09a91447</guid>
      <pubDate>Tue, 30 Jun 2009 11:34:00 GMT</pubDate>
    </item>
    <item>
      <title>Cambridge usergroup meeting on Monday 6th - SQL 2008</title>
      <description>&lt;p&gt;Don&amp;#39;t forget if you are in the Cambridge area on Monday 
(6th July 2009) we are doing another usergroup meeting.&lt;/p&gt;
&lt;p&gt;This one is going to be on SQL Server 2008 features. &lt;/p&gt;
&lt;p&gt;We are holding this at the head quarters of Redgate software who are kindly 
sponsoring the event.&lt;/p&gt;
&lt;p&gt;To register go to &lt;a href="http://sqlserverfaq.com/events/183/SQL-Server-User-Group-Cambridge-SQL-Server-2008.aspx"&gt;http://sqlserverfaq.com/events/183/SQL-Server-User-Group-Cambridge-SQL-Server-2008.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I look forward to seeing you there.&lt;/p&gt;
&lt;hr /&gt;
-



 &lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=11930" width="1" height="1"&gt;</description>
      <link>http://sqlblogcasts.com/blogs/simons/archive/2009/06/30/Cambridge-usergroup-meeting-on-Monday-6th---SQL-2008.aspx</link>
      <source url="http://sqlblogcasts.com/blogs/">SQL Server Community Blogs</source>
      <author>simonsabin</author>
      <dc:creator>simonsabin</dc:creator>
      <guid isPermaLink="False">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:11930</guid>
      <pubDate>Tue, 30 Jun 2009 09:19:11 GMT</pubDate>
    </item>
    <item>
      <title>Don't destory your certificate if you dabble with SQL 2008 Encryption</title>
      <description>&lt;p&gt;Martin is continuing to post some great new posts on his 
blog. I thought the last one is a real nasty one.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://sqlblogcasts.com/blogs/martinbell/archive/2009/06/29/After-disabling-tde-you-still-requires-certificates-to-restore-the-database.aspx"&gt;http://sqlblogcasts.com/blogs/martinbell/archive/2009/06/29/After-disabling-tde-you-still-requires-certificates-to-restore-the-database.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If you have enabled TDE on a database and encrypted some data then remove the 
TDE and backup, you may not be able to restore that backup if you don&amp;#39;t have the 
certificate. &lt;/p&gt;
&lt;p&gt;I am guessing that this is to do with the encryption when you turn TDE on 
being a background task, I expect the same is true in reverse, i.e. pages stay 
encrypted until a background process decrypts them.&lt;/p&gt;
&lt;p&gt;I wonder if the database ever gets back to a totally unencrypted 
version&lt;/p&gt;
&lt;hr /&gt;
-



 &lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=11928" width="1" height="1"&gt;</description>
      <link>http://sqlblogcasts.com/blogs/simons/archive/2009/06/30/Don-t-destory-your-certificate-if-you-dabble-with-SQL-2008-Encryption.aspx</link>
      <source url="http://sqlblogcasts.com/blogs/">SQL Server Community Blogs</source>
      <author>simonsabin</author>
      <dc:creator>simonsabin</dc:creator>
      <guid isPermaLink="False">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:11928</guid>
      <pubDate>Tue, 30 Jun 2009 09:11:37 GMT</pubDate>
    </item>
    <item>
      <title>How to stop that annoying beep on your server</title>
      <description>&lt;p&gt;Many years ago&amp;nbsp;I was working on a project that had 
some large batch processing in it. To do this processing we had some dedicated 
servers, one of which sat under the desk next to me.&lt;/p&gt;
&lt;p&gt;Apart from the noise of the fan soudning like we had actually bought a jet 
fighter the most annoying thing about this processing was that it resulted 
caused the servers beep to continually sound. Something in the code caused it to 
fire. &lt;/p&gt;
&lt;p&gt;Boy it was annoying.&lt;/p&gt;
&lt;p&gt;We were never able to find out how to stop it, I think in the end we 
disconnected it. Well last week I found out and it was so annoyingly simple. 
&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;net stop beep&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Yep thats it, thanks to the trainer that pointed this out last week. As you 
can imagine, having 12 training machines all beeping is not something you really 
want&lt;/p&gt;
&lt;p&gt;To permanently stop it you have to disable the service using &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;sc config beep start= disabled&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Whats really odd is that beep doesn&amp;#39;t appear in the list of 
services&lt;/p&gt;
&lt;hr /&gt;
-



 &lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=11925" width="1" height="1"&gt;</description>
      <link>http://sqlblogcasts.com/blogs/simons/archive/2009/06/30/How-to-stop-that-annoying-beep-on-your-server.aspx</link>
      <source url="http://sqlblogcasts.com/blogs/">SQL Server Community Blogs</source>
      <author>simonsabin</author>
      <dc:creator>simonsabin</dc:creator>
      <guid isPermaLink="False">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:11925</guid>
      <pubDate>Tue, 30 Jun 2009 05:45:37 GMT</pubDate>
    </item>
    <item>
      <title>After disabling TDE you still requires the certificate to restore the database</title>
      <description>Missing certificates can cause problems when restoring databases even if they are not being used!...(&lt;a href="http://sqlblogcasts.com/blogs/martinbell/archive/2009/06/29/After-disabling-tde-you-still-requires-certificates-to-restore-the-database.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=11924" width="1" height="1"&gt;</description>
      <link>http://sqlblogcasts.com/blogs/martinbell/archive/2009/06/29/After-disabling-tde-you-still-requires-certificates-to-restore-the-database.aspx</link>
      <source url="http://sqlblogcasts.com/blogs/">SQL Server Community Blogs</source>
      <author>MartinBell</author>
      <dc:creator>MartinBell</dc:creator>
      <guid isPermaLink="False">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:11924</guid>
      <pubDate>Mon, 29 Jun 2009 18:46:00 GMT</pubDate>
    </item>
    <item>
      <title>DTLoggedExec 0.2.2.0: Here comes CSV Logging!</title>
      <description>&lt;p&gt;In these last days I've released the latest version of DTLoggedExec. Now it has reached version 0.2.2.0.&lt;/p&gt;
&lt;p&gt;I planned the release to be done in May, but I added a l lot of stuff and then I realized that logging so much information without being able to automatically import it into SQL Server for further analsys has no clue.&lt;/p&gt;
&lt;p&gt;So I decided to hold on a little bit and also improve the DTLoggedExec db that I firstly released with version 0.2.1.4 just as an example of what can be done with the Data Profiling featture, and that news has grown to be official repository of all the data the DTLoggedExec can log.&lt;/p&gt;
&lt;p&gt;Of course with the added capability to log to CSV file, this feature was really needed.&lt;/p&gt;
&lt;p&gt;This new feature brought also the need to be able to associate CSV Logging with DataFlow Profiling, so I had to change the code a little bit so that everything can get a consistent and unique Execution ID, which allows the data to be tied all togheter, not matter if it comes from DataFlow Profiling or CSV Logging.&lt;/p&gt;
&lt;p&gt;Add this with some bug fixed and a very handy feature that allows you to get rid of the complex SET syntax to make yout package parametric and you can imagine that some work had to be done.&lt;/p&gt;
&lt;p&gt;Plus, add that before releasing any new release I want to test it for a while on myself, just to be sure that very basic bug does get unnoticed, at voilà, some months of delay.&lt;/p&gt;
&lt;p&gt;Anyway, now its there, and I'm sure you'll enjoy the new features:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;
    &lt;div&gt;Added logging of expression used by variables for which the "EvaluateAsExpression" property is true.&lt;/div&gt;
    &lt;/li&gt;
    &lt;li&gt;Fixed the bug the prevented to log properly Custom Events (CodePlex id# 20513)&lt;/li&gt;
    &lt;li&gt;Fixed a bug that prevented to log properly all the container properties in case of error&lt;/li&gt;
    &lt;li&gt;Added support for "Params" commandline options&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Released CSV log provider&lt;/strong&gt;&lt;/li&gt;
    &lt;li&gt;Handled exceptions when loaded configuration tries to configure non-existing objects&lt;/li&gt;
    &lt;li&gt;Changed the ILogProvider interface to allow Log Provider to get the ExecutionGUID value from the main program&lt;/li&gt;
    &lt;li&gt;Changed the Console and Null log providers to support the new ILogProvider interface&lt;/li&gt;
    &lt;li&gt;Changed the header of the *.dtsDataFlowProfile in order to store package, version and execution GUIDs&lt;/li&gt;
    &lt;li&gt;Changed .sql files to import Profiled DataFlow data in SQL Server&lt;/li&gt;
    &lt;li&gt;Updated DTLoggedExecDB database&lt;/li&gt;
    &lt;strong&gt;&lt;/strong&gt;
    &lt;li&gt;&lt;strong&gt;Released scripts to load CSV data proceduced by CSV Log Provider into SQL Server&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I'm now in the process of updating the documentation. I plan to be able to do it during this week and weekend, but using the new feature is quite easy and as usual I have included in released code some samples to show how to use them.&lt;/p&gt;
&lt;p&gt;So, if you cannot wait, go and play, otherwise just hold on a while, while I update the documentation here:&lt;/p&gt;
&lt;p&gt;&lt;font face=""&gt;&lt;a href="http://dtloggedexec.davidemauri.it/MainPage.ashx"&gt;http://dtloggedexec.davidemauri.it/MainPage.ashx&lt;/a&gt; &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;One last notice about the new CSV Log Provider. This is completely functional and you can start to use it right now, but is just the first release. I plan to improve it more and more. I have to deep test it for performance impact, so play with it freely but be warned that performance may be lower then the Console Log Provider. Inside it pack data into XML format so that it can be stored in SQL Server easily, but this has some costs (You know, XML is flexble, standard, whatever you want, but surealy is not performant).&lt;/p&gt;
&lt;p&gt;In future I plan to change a little bit the Log Provider interface again so that everything can be redirected to the Log Provider, also the initial messages, so that in the CSV log can be put everything can currently be found in the Console Log Provider, event the initialization messages, so inside SQL Server you can have the complete picture of what happened, right from the initialization of DTLoggedExec, just as it now happens with the Console Log Provider. Anyway, and I wanted to share it with you so that you can have an idea of future improvements, but for now just playing with the CSV log provider can solve a lot of nice problems. For example Auditing packages :).&lt;/p&gt;
&lt;p&gt;More on that coming.... ;)&lt;/p&gt;&lt;img src="http://weblogs.sqlteam.com/dmauri/aggbug/60945.aspx" width="1" height="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=mtYbrGdZZII:vwzZD0Ifd7k:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=mtYbrGdZZII:vwzZD0Ifd7k:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=mtYbrGdZZII:vwzZD0Ifd7k:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?i=mtYbrGdZZII:vwzZD0Ifd7k:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=mtYbrGdZZII:vwzZD0Ifd7k:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?i=mtYbrGdZZII:vwzZD0Ifd7k:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=mtYbrGdZZII:vwzZD0Ifd7k:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=mtYbrGdZZII:vwzZD0Ifd7k:gRsNgB-aSSA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=gRsNgB-aSSA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=mtYbrGdZZII:vwzZD0Ifd7k:as7VaYKENsE"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=as7VaYKENsE" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlteamcomWeblogs/~4/mtYbrGdZZII" height="1" width="1" /&gt;</description>
      <link>http://feedproxy.google.com/~r/SqlteamcomWeblogs/~3/mtYbrGdZZII/60945.aspx</link>
      <source url="http://weblogs.sqlteam.com/mainfeed2.aspx">The SQLTeam.com Weblogs</source>
      <author>Davide Mauri</author>
      <dc:creator>Davide Mauri</dc:creator>
      <comments>http://weblogs.sqlteam.com/dmauri/archive/2009/06/29/60945.aspx#comment</comments>
      <guid isPermaLink="False">http://weblogs.sqlteam.com/dmauri/archive/2009/06/29/60945.aspx</guid>
      <pubDate>Mon, 29 Jun 2009 17:40:38 GMT</pubDate>
    </item>
    <item>
      <title>Interesting issue with Filtered indexes.</title>
      <description>&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;Recently, an ISV I work with ran into an interesting problem with Filtered Indexes.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;The application does all SQL INSERT, DELETE, and UPDATE operations using individual stored procedures. To improve performance, they decided to create a Filtered Index (new in SQL 2008) to restrict the data such that it does not contain NULL values, in this case drastically reducing the number of rows in the index. See documentation here: &lt;/FONT&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/ms175049.aspx"&gt;&lt;FONT face=Calibri color=#0000ff size=3&gt;http://msdn.microsoft.com/en-us/library/ms175049.aspx&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;SPAN style="COLOR:black;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;This all worked fine, until months later, when the ‘UPDATE’ stored procedure was updated as part of a routine application upgrade. The stored proc was replaced with a newer version using a TSQL script. After adding the ‘new’ stored proc the application was tested and the following was observed;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpFirst style="MARGIN:0in 0in 0pt 0.5in;TEXT-INDENT:-0.25in;mso-list:l0 level1 lfo1;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol;mso-themecolor:text1;"&gt;&lt;SPAN style="mso-list:Ignore;"&gt;&lt;FONT size=3&gt;·&lt;/FONT&gt;&lt;SPAN style="FONT:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;the SELECT statements accessing the table continued to use the filtered index&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpMiddle style="MARGIN:0in 0in 0pt 0.5in;TEXT-INDENT:-0.25in;mso-list:l0 level1 lfo1;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol;mso-themecolor:text1;"&gt;&lt;SPAN style="mso-list:Ignore;"&gt;&lt;FONT size=3&gt;·&lt;/FONT&gt;&lt;SPAN style="FONT:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;the ‘INSERT’, and ‘DELETE’ stored procs continued to work&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpLast style="MARGIN:0in 0in 10pt 0.5in;TEXT-INDENT:-0.25in;mso-list:l0 level1 lfo1;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol;mso-themecolor:text1;"&gt;&lt;SPAN style="mso-list:Ignore;"&gt;&lt;FONT size=3&gt;·&lt;/FONT&gt;&lt;SPAN style="FONT:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;However, the modified ‘UPDATE’ stored proc returned the following error:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;SPAN style="COLOR:red;"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;InnerException: System.Data.SqlClient.SqlException: UPDATE failed because the following SET options have incorrect settings: 'QUOTED_IDENTIFIER'. Verify that SET options are correct for use with indexed views and/or indexes on computed columns and/or filtered indexes and/or query notifications and/or XML data type methods and/or spatial index operations.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;SPAN style="COLOR:black;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Note that the error message is very explicit and actually points us to the source of the problem. Can you guess what it is?&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="COLOR:black;mso-themecolor:text1;"&gt;You are correct! The TSQL script used SET options that were set differently for the new ‘UPDATE’ stored proc than they were originally, and they don’t conform to the rules required to utilize Filtered Indexes. &lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;In this case, the &lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;SET QUOTED_IDENTIFIER was set to an invalid setting.&lt;/SPAN&gt;&lt;SPAN style="COLOR:navy;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;SPAN style="COLOR:black;mso-themecolor:text1;"&gt;&lt;FONT face=Calibri size=3&gt;The solution to the problem was to recreate the stored proc using the ‘correct’ settings required to use Filtered indexes, documented here: &lt;/FONT&gt;&lt;/SPAN&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/ms188783.aspx"&gt;&lt;FONT face=Calibri color=#0000ff size=3&gt;http://msdn.microsoft.com/en-us/library/ms188783.aspx&lt;/FONT&gt;&lt;/A&gt;&lt;SPAN style="COLOR:black;mso-themecolor:text1;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;SPAN style="COLOR:black;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;The following simplified TSQL example shows the problem and the solution.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;SPAN style="COLOR:black;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;NOTE: the fact that Stored Procedures were used is important, because they ‘inherit’ the SET statement values they were created with, and NOT the values they are executed with. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;USE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;USE&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;master&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;CREATE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;DATABASE&lt;/SPAN&gt; FI_Test&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;USE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; FI_Test&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;SET&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;ANSI_NULLS&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;ON&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;SET&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;QUOTED_IDENTIFIER&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;ON&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;CREATE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;TABLE&lt;/SPAN&gt; [FactSalesQuota]&lt;SPAN style="COLOR:gray;"&gt;(&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;[SalesQuotaKey] [int] &lt;SPAN style="COLOR:blue;"&gt;IDENTITY&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;1&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;1&lt;SPAN style="COLOR:gray;"&gt;)&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;NULL,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;[EmployeeKey] [int] &lt;SPAN style="COLOR:gray;"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;NULL,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;[DateKey] [int] &lt;SPAN style="COLOR:gray;"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;NULL,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;[CalendarYear] [smallint] &lt;SPAN style="COLOR:gray;"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;NULL,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;[CalendarQuarter] [tinyint] &lt;SPAN style="COLOR:gray;"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;NULL,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;[SalesAmountQuota] [money] &lt;SPAN style="COLOR:gray;"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;NULL,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;CONSTRAINT&lt;/SPAN&gt; [PK_FactSalesQuota_SalesQuotaKey] &lt;SPAN style="COLOR:blue;"&gt;PRIMARY&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;KEY&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;CLUSTERED&lt;/SPAN&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:gray;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;[SalesQuotaKey] &lt;SPAN style="COLOR:blue;"&gt;ASC&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;)&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;ON&lt;/SPAN&gt; [PRIMARY]&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:gray;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;)&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;ON&lt;/SPAN&gt; [PRIMARY]&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;CREATE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;NONCLUSTERED&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;INDEX&lt;/SPAN&gt; FI_FactSalesQuota &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;ON&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; FactSalesQuota&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;Employeekey&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;CalendarQuarter&lt;SPAN style="COLOR:gray;"&gt;)&lt;/SPAN&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;WHERE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; CalendarYear &lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; 2009 &lt;SPAN style="COLOR:green;"&gt;-- &amp;lt;---- This makes it a Filtered index&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;INSERT&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; FactSalesQuota &lt;SPAN style="COLOR:blue;"&gt;values&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;53&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;20090101&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;2009&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;4&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; 37000.00&lt;SPAN style="COLOR:gray;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;SELECT&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:gray;"&gt;*&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;FROM&lt;/SPAN&gt; FactSalesQuota&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;CREATE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;PROCEDURE&lt;/SPAN&gt; UPDATE_FactSalesQuota &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;@EmployeeKey &lt;SPAN style="COLOR:blue;"&gt;int&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;@CalendarYear &lt;SPAN style="COLOR:blue;"&gt;smallint&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;@CalendarQuarter &lt;SPAN style="COLOR:blue;"&gt;tinyint&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;@SalesAmountQuota &lt;SPAN style="COLOR:blue;"&gt;money&lt;/SPAN&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;AS&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;UPDATE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; FactSalesQuota &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;SET&lt;/SPAN&gt; SalesAmountQuota &lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;@SalesAmountQuota&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;WHERE&lt;/SPAN&gt;&lt;SPAN style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;EmployeeKey &lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; @EmployeeKey &lt;SPAN style="COLOR:gray;"&gt;and&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-tab-count:2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CalendarYear &lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; @CalendarYear &lt;SPAN style="COLOR:gray;"&gt;and&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-tab-count:2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CalendarQuarter &lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; @CalendarQuarter&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;EXECUTE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; UPDATE_FactSalesQuota&lt;SPAN style="COLOR:blue;"&gt; &lt;/SPAN&gt;53&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;2009&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;4&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;50000.00&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;SELECT&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:gray;"&gt;*&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;FROM&lt;/SPAN&gt; FactSalesQuota&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:green;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;--- this was the script to update the sp&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;use&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; FI_Test&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:maroon;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;sp_rename&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; UPDATE_FactSalesQuota &lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; UPDATE_FactSalesQuota_V1&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;SET&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;ANSI_NULLS&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;ON&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;SET&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;QUOTED_IDENTIFIER&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;OFF&lt;/SPAN&gt; &lt;SPAN style="COLOR:green;"&gt;-- &amp;lt;------ HERE is what caused the error&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:green;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;--SET QUOTED_IDENTIFIER ON -- &amp;lt;------ it will work if this is set correctly&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;CREATE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;PROCEDURE&lt;/SPAN&gt; UPDATE_FactSalesQuota &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;@EmployeeKey &lt;SPAN style="COLOR:blue;"&gt;int&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;@CalendarYear &lt;SPAN style="COLOR:blue;"&gt;smallint&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;@CalendarQuarter &lt;SPAN style="COLOR:blue;"&gt;tinyint&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;@SalesAmountQuota &lt;SPAN style="COLOR:blue;"&gt;money&lt;/SPAN&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;AS&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;UPDATE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; FactSalesQuota &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;SET&lt;/SPAN&gt;&lt;SPAN style="mso-tab-count:1;"&gt;&amp;nbsp; &lt;/SPAN&gt;SalesAmountQuota &lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;@SalesAmountQuota&lt;SPAN style="COLOR:gray;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;DateKey &lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; &lt;SPAN style="COLOR:fuchsia;"&gt;cast&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;((&lt;/SPAN&gt;&lt;SPAN style="COLOR:fuchsia;"&gt;CONVERT&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;char&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;8&lt;SPAN style="COLOR:gray;"&gt;)&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="COLOR:fuchsia;"&gt;getdate&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(),&lt;/SPAN&gt; 112&lt;SPAN style="COLOR:gray;"&gt;))&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;as&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;int&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;WHERE&lt;/SPAN&gt;&lt;SPAN style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;EmployeeKey &lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; @EmployeeKey &lt;SPAN style="COLOR:gray;"&gt;and&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-tab-count:2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CalendarYear &lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; @CalendarYear &lt;SPAN style="COLOR:gray;"&gt;and&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-tab-count:2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CalendarQuarter &lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; @CalendarQuarter&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:green;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;--this fails&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;EXECUTE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; UPDATE_FactSalesQuota&lt;SPAN style="COLOR:blue;"&gt; &lt;/SPAN&gt;53&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;2009&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;4&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;52000.00&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;SELECT&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:gray;"&gt;*&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;FROM&lt;/SPAN&gt; FactSalesQuota&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:green;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;-- Now go back fix the script, and retry the sript and now it will work&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:green;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:green;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:green;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
Cross Posted from http://blogs.microsoft.com/mssqlisv&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9808877" width="1" height="1"&gt;</description>
      <link>http://blogs.msdn.com/sqlprogrammability/archive/2009/06/29/interesting-issue-with-filtered-indexes.aspx</link>
      <source url="http://blogs.msdn.com/sqlprogrammability/default.aspx">SQL Programmability &amp; API Development Team Blog</source>
      <author>mssqlisv</author>
      <dc:creator>mssqlisv</dc:creator>
      <comments>http://blogs.msdn.com/sqlprogrammability/comments/9808877.aspx</comments>
      <guid isPermaLink="False">91d46819-8472-40ad-a661-2c78acb4018c:9808877</guid>
      <pubDate>Mon, 29 Jun 2009 15:56:00 GMT</pubDate>
    </item>
    <item>
      <title>SQL Server version has a known compatibility issues with Windows 7 RC. This warning is genuine and applies to all SQL Server editions, including all Express editions.</title>
      <description>There is no need to guess about the rootcause of the above error message, as it clearly mentions about compatibility issues as a warning.... read more !...(&lt;a href="http://sqlblogcasts.com/blogs/ssqanet/archive/2009/06/29/sql-server-version-has-a-known-compatibility-issues-with-windows-7-rc-this-warning-is-genuine-and-applies-to-all-sql-server-editions-including-all-express-editions.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=11921" width="1" height="1"&gt;</description>
      <link>http://sqlblogcasts.com/blogs/ssqanet/archive/2009/06/29/sql-server-version-has-a-known-compatibility-issues-with-windows-7-rc-this-warning-is-genuine-and-applies-to-all-sql-server-editions-including-all-express-editions.aspx</link>
      <source url="http://sqlblogcasts.com/blogs/">SQL Server Community Blogs</source>
      <author>ssqa.net</author>
      <dc:creator>ssqa.net</dc:creator>
      <guid isPermaLink="False">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:11921</guid>
      <pubDate>Mon, 29 Jun 2009 06:35:00 GMT</pubDate>
    </item>
    <item>
      <title>Hyperlinks in custom reports</title>
      <description>&lt;p&gt;One feature introduced in SQL Server 2005 is reporting in management studio. 
You have a set of standard reports that allow you to see in a nice report format 
output from dmvs and the default system background trace. Whats neat is that you 
can write your own custom reports. For those that long after the taskpad view of 
a database from SQL 2000 Enterprise manager with the help from Jasper 
Smith&amp;nbsp;I created this &lt;a href="http://sqlblogcasts.com/blogs/simons/archive/2007/03/28/Update-to-the-taskpad-custom-report.aspx"&gt;http://sqlblogcasts.com/blogs/simons/archive/2007/03/28/Update-to-the-taskpad-custom-report.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The custom report feature is almost fantastic, there are 3 main features I 
think make them awkward to use. &lt;/p&gt;
&lt;p&gt;1. You can select text from the report and copy it&lt;br /&gt;2. You can&amp;#39;t add 
additional parameters to allow additional filtering, i.e. filter audit changes 
for today.&lt;br /&gt;3. You can&amp;#39;t have hyperlinks.&lt;/p&gt;
&lt;p&gt;The last one I raised a connect item for &lt;span style="FONT-FAMILY:'Calibri','sans-serif';FONT-SIZE:11pt;mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-GB;mso-fareast-language:EN-GB;mso-bidi-language:AR-SA;"&gt;&lt;a href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=240407"&gt;https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=240407&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-FAMILY:'Calibri','sans-serif';FONT-SIZE:11pt;mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-GB;mso-fareast-language:EN-GB;mso-bidi-language:AR-SA;"&gt;If 
we had this you could write reports that had links to KB articles, blog posts, 
or internal KB systems. Similar to what most monitoring systems 
provide.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-FAMILY:'Calibri','sans-serif';FONT-SIZE:11pt;mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-GB;mso-fareast-language:EN-GB;mso-bidi-language:AR-SA;"&gt;If 
you think this is a good idea then please vote on the connect item. I&amp;#39;ve been 
asked by the tools team to see if it is something people want.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-FAMILY:'Calibri','sans-serif';FONT-SIZE:11pt;mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-GB;mso-fareast-language:EN-GB;mso-bidi-language:AR-SA;"&gt;Some 
other connect items that you might be interested in supporting if you think they 
are worthwhile.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-FAMILY:'Calibri','sans-serif';FONT-SIZE:11pt;mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-GB;mso-fareast-language:EN-GB;mso-bidi-language:AR-SA;"&gt;Use 
expressions for data sources - &lt;/span&gt;&lt;span style="FONT-FAMILY:'Calibri','sans-serif';FONT-SIZE:11pt;mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-GB;mso-fareast-language:EN-GB;mso-bidi-language:AR-SA;"&gt;&lt;a href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=238233"&gt;https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=238233&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-FAMILY:'Calibri','sans-serif';FONT-SIZE:11pt;mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-GB;mso-fareast-language:EN-GB;mso-bidi-language:AR-SA;"&gt;Be 
able to combine data from different data sources - &lt;a href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=240268"&gt;https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=240268&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-FAMILY:'Calibri','sans-serif';FONT-SIZE:11pt;mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-GB;mso-fareast-language:EN-GB;mso-bidi-language:AR-SA;"&gt;Be 
able to run reports against SQL 2000 database - &lt;a href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=240476"&gt;https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=240476&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-FAMILY:'Calibri','sans-serif';FONT-SIZE:11pt;mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-GB;mso-fareast-language:EN-GB;mso-bidi-language:AR-SA;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;&lt;hr /&gt;
-



 &lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=11918" width="1" height="1"&gt;</description>
      <link>http://sqlblogcasts.com/blogs/simons/archive/2009/06/29/Hyperlinks-in-custom-reports.aspx</link>
      <source url="http://sqlblogcasts.com/blogs/">SQL Server Community Blogs</source>
      <author>simonsabin</author>
      <dc:creator>simonsabin</dc:creator>
      <guid isPermaLink="False">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:11918</guid>
      <pubDate>Mon, 29 Jun 2009 03:31:50 GMT</pubDate>
    </item>
    <item>
      <title>Microsoft Connect - Enhanced Syntax For Insert Into Statement</title>
      <description>&lt;p&gt;I've posted a feedback on Microsoft Connect about how to enhance the INSERT INTO syntax.&lt;br /&gt;
Especially for INSERT INTO ... EXEC ...&lt;br /&gt;
&lt;br /&gt;
Sometimes when you need the result from a stored procedure, the SP itself returns two (or more) resultsets.&lt;br /&gt;
And it's only possibly to fetch and store the first resultset.&lt;br /&gt;
&lt;br /&gt;
What I have suggested is an enhanced syntax for INSERT INTO ... EXEC, like this&lt;/p&gt;
&lt;p&gt;INSERT INTO Table1 (Col1, Col2), Table2 (ColX, ColY, ColZ)&lt;br /&gt;
EXEC usp_MyStoredProcedure @Param1, @Param2&lt;br /&gt;
&lt;br /&gt;
In this example, usp_MyStoredProcedure returns three resultsets, of which I want to store the two first.&lt;br /&gt;
First resultset has two columns, and second resultset has three columns.&lt;br /&gt;
&lt;br /&gt;
Let Microsoft know what you think about this suggestion.&lt;br /&gt;
&lt;a target="_blank" href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=470881"&gt;https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=470881&lt;/a&gt;&lt;br /&gt;
&lt;/p&gt;&lt;img src="http://weblogs.sqlteam.com/peterl/aggbug/60943.aspx" width="1" height="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=-RUaRiV2oBU:JG4AFMUKybE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=-RUaRiV2oBU:JG4AFMUKybE:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=-RUaRiV2oBU:JG4AFMUKybE:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?i=-RUaRiV2oBU:JG4AFMUKybE:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=-RUaRiV2oBU:JG4AFMUKybE:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?i=-RUaRiV2oBU:JG4AFMUKybE:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=-RUaRiV2oBU:JG4AFMUKybE:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=-RUaRiV2oBU:JG4AFMUKybE:gRsNgB-aSSA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=gRsNgB-aSSA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=-RUaRiV2oBU:JG4AFMUKybE:as7VaYKENsE"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=as7VaYKENsE" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlteamcomWeblogs/~4/-RUaRiV2oBU" height="1" width="1" /&gt;</description>
      <link>http://feedproxy.google.com/~r/SqlteamcomWeblogs/~3/-RUaRiV2oBU/Microsoft-Connect---Enhanced-Syntax-For-Insert-Into-Statement.aspx</link>
      <source url="http://weblogs.sqlteam.com/mainfeed2.aspx">The SQLTeam.com Weblogs</source>
      <author>Peter Larsson</author>
      <dc:creator>Peter Larsson</dc:creator>
      <comments>http://weblogs.sqlteam.com/peterl/archive/2009/06/27/Microsoft-Connect---Enhanced-Syntax-For-Insert-Into-Statement.aspx#comment</comments>
      <guid isPermaLink="False">http://weblogs.sqlteam.com/peterl/archive/2009/06/27/Microsoft-Connect---Enhanced-Syntax-For-Insert-Into-Statement.aspx</guid>
      <pubDate>Sat, 27 Jun 2009 16:06:54 GMT</pubDate>
    </item>
    <item>
      <title>Microsoft Connect - SSMS Debugger Issue</title>
      <description>&lt;p&gt;I've found an issue with the Debugger for SQL Server 2008 Management Studio a while ago.&lt;br /&gt;
This is my way to ask you to endorse a fix&lt;br /&gt;
&lt;a target="_blank" href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=374183"&gt;https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=374183&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Please let Microsoft know what you think about this suggestion.&lt;br /&gt;
&lt;/p&gt;&lt;img src="http://weblogs.sqlteam.com/peterl/aggbug/60942.aspx" width="1" height="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=IXBoPCHtZgk:zPRlsR8xUrk:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=IXBoPCHtZgk:zPRlsR8xUrk:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=IXBoPCHtZgk:zPRlsR8xUrk:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?i=IXBoPCHtZgk:zPRlsR8xUrk:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=IXBoPCHtZgk:zPRlsR8xUrk:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?i=IXBoPCHtZgk:zPRlsR8xUrk:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=IXBoPCHtZgk:zPRlsR8xUrk:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=IXBoPCHtZgk:zPRlsR8xUrk:gRsNgB-aSSA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=gRsNgB-aSSA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=IXBoPCHtZgk:zPRlsR8xUrk:as7VaYKENsE"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=as7VaYKENsE" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlteamcomWeblogs/~4/IXBoPCHtZgk" height="1" width="1" /&gt;</description>
      <link>http://feedproxy.google.com/~r/SqlteamcomWeblogs/~3/IXBoPCHtZgk/Microsoft-Connect---SSMS-Debugger-Issue.aspx</link>
      <source url="http://weblogs.sqlteam.com/mainfeed2.aspx">The SQLTeam.com Weblogs</source>
      <author>Peter Larsson</author>
      <dc:creator>Peter Larsson</dc:creator>
      <comments>http://weblogs.sqlteam.com/peterl/archive/2009/06/27/Microsoft-Connect---SSMS-Debugger-Issue.aspx#comment</comments>
      <guid isPermaLink="False">http://weblogs.sqlteam.com/peterl/archive/2009/06/27/Microsoft-Connect---SSMS-Debugger-Issue.aspx</guid>
      <pubDate>Sat, 27 Jun 2009 16:01:42 GMT</pubDate>
    </item>
    <item>
      <title>Forced Parameterization: A Turbo Button?</title>
      <description>&lt;font size="3"&gt;
&lt;p style="MARGIN:0in 0in 10pt;" class="MsoNormal"&gt;I never had the need to turn on the PARAMETERIZATION FORCED database option until this week.&lt;span style="mso-spacerun:yes;"&gt;  &lt;/span&gt;We pretty much use only stored procedures for our internal applications so the execution plans are almost always in cache and reused.&lt;span style="mso-spacerun:yes;"&gt;  &lt;/span&gt;This practice of using parameterized stored procedure calls, together with attention to detail in query and index tuning, allows us to comfortably handle several thousand requests per second on commodity hardware without taking special measures.&lt;/p&gt;
&lt;h1 style="MARGIN:10pt 0in 0pt;"&gt;&lt;font color="#17365d" size="5"&gt;The Perfect Storm&lt;/font&gt;&lt;/h1&gt;
&lt;p style="MARGIN:0in 0in 10pt;" class="MsoNormal"&gt;We acquired a third-party application which had to sustain thousands of batch requests per second in order to keep up with our peak demand.&lt;span style="mso-spacerun:yes;"&gt;  &lt;/span&gt;Our first attempt to use the application out-of-the box failed miserably when the 16-core database server quickly hit 100% CPU and stayed there.&lt;span style="mso-spacerun:yes;"&gt;  &lt;/span&gt;An examination of the most frequently run query soon revealed why CPU was so high.&lt;span style="mso-spacerun:yes;"&gt;  &lt;/span&gt;Not only was the moderately complex query not parameterized, each invocation required a full table scan. &lt;span style="mso-spacerun:yes;"&gt; &lt;/span&gt;The schema (&lt;a href="http://en.wikipedia.org/wiki/Entity-Attribute-Value_model"&gt;&lt;font color="#800080"&gt;EAV model&lt;/font&gt;&lt;/a&gt;, missing primary keys and indexes), application code (ad-hoc, non-parameterized queries) and inattention to indexing seemed the perfect storm to guarantee failure.&lt;span style="mso-spacerun:yes;"&gt;  &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0in 0in 10pt;" class="MsoNormal"&gt;Our hands were tied in what the vendor could/would do to address our performance concerns.&lt;span style="mso-spacerun:yes;"&gt;  &lt;/span&gt;We worked with the vendor to optimize indexes and this brought the CPU down to about 65% but the batch requests/sec rate and slow response time was still unacceptable. &lt;span style="mso-spacerun:yes;"&gt;  &lt;/span&gt;We needed to increase performance by at least an order of magnitude to meet SLAs.&lt;/p&gt;
&lt;h1 style="MARGIN:10pt 0in 0pt;"&gt;&lt;font color="#17365d" size="5"&gt;The Perfect Fix&lt;/font&gt;&lt;/h1&gt;
&lt;p style="MARGIN:0in 0in 10pt;" class="MsoNormal"&gt;I then recalled an experience that &lt;a href="http://sqlblog.com/blogs/adam_machanic/default.aspx"&gt;&lt;font color="#800080"&gt;SQL Server MVP Adam Machanic&lt;/font&gt;&lt;/a&gt; shared not long ago:&lt;/p&gt;
&lt;p style="MARGIN:0in 0in 10pt;" class="MsoNormal"&gt;
&lt;/p&gt;&lt;table style="BORDER-BOTTOM:medium none;BORDER-LEFT:medium none;MARGIN:auto auto auto 22.1pt;BORDER-COLLAPSE:collapse;BORDER-TOP:medium none;BORDER-RIGHT:medium none;mso-padding-alt:0in 5.4pt 0in 5.4pt;mso-border-alt:solid black .5pt;mso-yfti-tbllook:1184;" class="MsoTableGrid" cellspacing="0" cellpadding="0"&gt;
    
        &lt;tr style="mso-yfti-irow:0;mso-yfti-firstrow:yes;mso-yfti-lastrow:yes;"&gt;
            &lt;td style="BORDER-BOTTOM:black 1pt solid;BORDER-LEFT:black 1pt solid;PADDING-BOTTOM:0in;BACKGROUND-COLOR:transparent;PADDING-LEFT:5.4pt;WIDTH:456.7pt;PADDING-RIGHT:5.4pt;BORDER-TOP:black 1pt solid;BORDER-RIGHT:black 1pt solid;PADDING-TOP:0in;mso-border-alt:solid black .5pt;"&gt;
            &lt;p style="MARGIN:0in 0in 10pt;" class="MsoNormal"&gt;&lt;em style="mso-bidi-font-style:normal;"&gt;&lt;font size="3"&gt;CPU was 95%+ at peak time (several thousand batch requests/second, via an ASP (classic) front end), and the peak time lasted 8+ hours every day.  The server was one of the big HP boxes -- not sure if it was a Superdome or some other model -- with something like 56 cores and 384 GB of RAM.  The database itself was only 40 or 50 GB, as I recall, so the entire thing was cached.  Long story short, I logged in during peak load, did a quick trace and noticed right away that none of the queries were parameterized.  I decided to throw caution to the wind and just go for it.  Flipped the thing into Forced Parameterization mode and held my breath as I watched the CPU counters *instantly* drop to 7% and stay there. I thought I'd broken the thing, but after checking my trace queries were running through the system same as before, and with the same number of errors (another story entirely &amp;lt;g&amp;gt;). Luckily the head IT guy happened to be watching his dashboard right as I made the change, and after seeing such an extreme result thought I was a god...&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
    
&lt;/table&gt;

&lt;p style="MARGIN:0in 0in 10pt;" class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;
&lt;p style="MARGIN:0in 0in 10pt;" class="MsoNormal"&gt;I knew of PARAMETERIZATION FORCED but never realized how big a difference the option could make until I learned of Adam's experience.&lt;span style="mso-spacerun:yes;"&gt;  &lt;/span&gt;I'm not quite as adventuresome as he is so I restored the production database to a separate environment for some cursory testing.&lt;span style="mso-spacerun:yes;"&gt;  &lt;/span&gt;To my amazement, I watched the rate of my single-threaded test jump from a few dozen batch requests/sec to several hundred immediately after I executed "&lt;strong style="mso-bidi-font-weight:normal;"&gt;ALTER DATABASE...SET PARAMETERIZATION FORCED&lt;/strong&gt;".&lt;span style="mso-spacerun:yes;"&gt;  &lt;/span&gt;CPU dropped by half even with the tenfold increase in throughput.&lt;span style="mso-spacerun:yes;"&gt;  &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0in 0in 10pt;" class="MsoNormal"&gt;The production improvement was even more impressive - the 16 core Dell R900 hasn't exceeded 8% CPU since the change.&lt;span style="mso-spacerun:yes;"&gt;  &lt;/span&gt;Response time is excellent, we have happy users and plenty of CPU headroom to spare.&lt;/p&gt;
&lt;h1 style="MARGIN:10pt 0in 0pt;"&gt;&lt;font color="#17365d" size="5"&gt;A Turbo Button?&lt;/font&gt;&lt;/h1&gt;
&lt;p style="MARGIN:0in 0in 10pt;" class="MsoNormal"&gt;Despite anecdotal success with PARAMETERIZATION FORCED, I wouldn't turn it on indiscriminately.&lt;span style="mso-spacerun:yes;"&gt;  &lt;/span&gt;When the PARAMETERIZATION FORCED database option is on, &lt;strong style="mso-bidi-font-weight:normal;"&gt;&lt;em style="mso-bidi-font-style:normal;"&gt;all queries are parameterized&lt;/em&gt;&lt;/strong&gt;, including complex ones.&lt;span style="mso-spacerun:yes;"&gt;  &lt;/span&gt;This is good in that compilation costs are avoided due to cache hits.&lt;span style="mso-spacerun:yes;"&gt;  &lt;/span&gt;The bad news is that a single plan might not be appropriate for all possible values of a given query.&lt;span style="mso-spacerun:yes;"&gt;  &lt;/span&gt;Worse overall performance will result when higher execution costs (due to sub-optimal plans) exceed compilation savings so you should understand the query mix before considering the option. &lt;/p&gt;
&lt;p style="MARGIN:0in 0in 10pt;" class="MsoNormal"&gt;In contrast, SQL Server parameterizes only relatively simple "no brainer" queries in the default PARAMETERIZATION SIMPLE mode.&lt;span style="mso-spacerun:yes;"&gt;  &lt;/span&gt;This behavior promotes reuse of plans for queries that will yield the same plan anyway regardless of the literal values in the query.&lt;span style="mso-spacerun:yes;"&gt;  &lt;/span&gt;Complex queries are not parameterized automatically so that the optimizer can generate the optimal plan for the values of the current query in the event of a cache miss. &lt;span style="mso-spacerun:yes;"&gt; &lt;/span&gt;The downside with simple parameterization, as Adam and I observed, is that complex queries not already in cache will incur costly compilation costs that are a CPU hog in a high-volume OLTP workload.&lt;/p&gt;
&lt;p style="MARGIN:0in 0in 10pt;" class="MsoNormal"&gt;There is also middle ground between PARAMETERIZATION SIMPLE and PARAMETERIZATION FORCED.&lt;span style="mso-spacerun:yes;"&gt;  &lt;/span&gt;One can use plans guides with PARAMETERIZATION SIMPLE to avoid compilation for selected queries while other complex queries are compiled as normal.&lt;span style="mso-spacerun:yes;"&gt;  &lt;/span&gt;In my case, a plan guide may have been a better option because the culprit was a single query rather than many different unpredictable ones.&lt;/p&gt;
&lt;p style="MARGIN:0in 0in 10pt;" class="MsoNormal"&gt;In my opinion, the best solution is to use stored procedures and/or parameterized queries in the first place.&lt;span style="mso-spacerun:yes;"&gt;  &lt;/span&gt;These methods provide the performance benefits of PARAMETERIZATION FORCED and add other security and application development benefits.&lt;span style="mso-spacerun:yes;"&gt;  &lt;/span&gt;Unfortunately, third-party vendors are notorious for not following parameterization Best Practices so DBAs need to keep PARAMETERIZATION FORCED and plan guides in their tool belt.&lt;/p&gt;
&lt;p style="MARGIN:0in 0in 10pt;" class="MsoNormal"&gt; &lt;/p&gt;
&lt;/font&gt;&lt;img src="http://weblogs.sqlteam.com/dang/aggbug/60944.aspx" width="1" height="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=QuYtCY7Rqdg:Y1bq94B9Wdc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=QuYtCY7Rqdg:Y1bq94B9Wdc:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=QuYtCY7Rqdg:Y1bq94B9Wdc:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?i=QuYtCY7Rqdg:Y1bq94B9Wdc:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=QuYtCY7Rqdg:Y1bq94B9Wdc:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?i=QuYtCY7Rqdg:Y1bq94B9Wdc:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=QuYtCY7Rqdg:Y1bq94B9Wdc:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=QuYtCY7Rqdg:Y1bq94B9Wdc:gRsNgB-aSSA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=gRsNgB-aSSA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?a=QuYtCY7Rqdg:Y1bq94B9Wdc:as7VaYKENsE"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlteamcomWeblogs?d=as7VaYKENsE" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlteamcomWeblogs/~4/QuYtCY7Rqdg" height="1" width="1" /&gt;</description>
      <link>http://feedproxy.google.com/~r/SqlteamcomWeblogs/~3/QuYtCY7Rqdg/Forced-Parameterization-A-Turbo-Button.aspx</link>
      <source url="http://weblogs.sqlteam.com/mainfeed2.aspx">The SQLTeam.com Weblogs</source>
      <author>Dan Guzman</author>
      <dc:creator>Dan Guzman</dc:creator>
      <comments>http://weblogs.sqlteam.com/dang/archive/2009/06/27/Forced-Parameterization-A-Turbo-Button.aspx#comment</comments>
      <guid isPermaLink="False">http://weblogs.sqlteam.com/dang/archive/2009/06/27/Forced-Parameterization-A-Turbo-Button.aspx</guid>
      <pubDate>Sat, 27 Jun 2009 10:47:17 GMT</pubDate>
    </item>
    <item>
      <title>Scripting schema AND data with SSMS in SQL 2008</title>
      <description>&lt;p&gt;
&lt;font face="verdana,geneva" size="2"&gt;It's very commonly known that you can use the Script Wizard in Management Studio to script out tables or even an entire database. It's NOT commonly known that in SQL Server 2008, the wizard was upgraded and you can now script out the data too. The feature isn't enabled by default, which is why not many people know about it, and I couldn't find it described in Books Online either, further contributing to it's obscurity - but it's definitely there. &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="verdana,geneva" size="2"&gt;If you go into the wizard, and go down to the Table/View Options, there's a setting 'Script Data'. Set that to True and you'll get a bunch of INSERT statements in the resulting script too. Very cool. &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="verdana,geneva" size="2"&gt;Here's a screenshot showing what I mean (click it for a 1024x768 version). &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="verdana,geneva" size="2"&gt;&amp;nbsp;&lt;a rel="nofollow" target="_blank" href="http://www.sqlskills.com/blogs/paul/content/binary/ScriptDataBig.JPG"&gt;&lt;img src="http://www.sqlskills.com/BLOGS/PAUL/image.axd?picture=2009%2f6%2fScriptDataSmall.jpg" alt="" width="448" height="336" /&gt;&lt;/a&gt;&lt;/font&gt; &lt;/p&gt;
&lt;p&gt;
&lt;font face="verdana,geneva" size="2"&gt;Enjoy!&lt;/font&gt; &lt;/p&gt;</description>
      <link>http://www.sqlskills.com/BLOGS/PAUL/post/Scripting-schema-AND-data-with-SSMS-in-SQL-2008.aspx</link>
      <source url="http://pipes.yahoo.com/pipes/pipe.info?_id=85142a7c17be56670fbddefa43f25c8d">SQLskills.com Aggregated Feed</source>
      <author>paul.nospam@nospam.sqlskills.com (paul)</author>
      <dc:creator>paul.nospam@nospam.sqlskills.com (paul)</dc:creator>
      <guid isPermaLink="False">http://www.sqlskills.com/BLOGS/PAUL/post.aspx?id=9494b5da-56de-4316-b4b1-f4efa5697e1a</guid>
      <pubDate>Fri, 26 Jun 2009 13:16:00 GMT</pubDate>
    </item>
  </channel>
</rss>