<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>SQL SERVER</title>
        <link>http://geekswithblogs.net/Gaurav/category/7931.aspx</link>
        <description>SQL SERVER</description>
        <language>en-US</language>
        <copyright>Gaurav Taneja</copyright>
        <managingEditor>taneja_gaurav@yahoo.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>Using Derived Tables</title>
            <link>http://geekswithblogs.net/Gaurav/archive/2011/01/10/143431.aspx</link>
            <description>&lt;h1 style="background: white; margin: auto 0in"&gt;&lt;font size="5"&gt;&lt;font color="#0066cc"&gt;&lt;font face="Verdana"&gt;Using Derived Tables to Simplify the SQL Server Query Process&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/h1&gt;
&lt;p style="background: white"&gt;&lt;font size="2"&gt;&lt;font face="Verdana"&gt;&lt;u&gt;&lt;strong&gt;Problem&lt;/strong&gt;&lt;/u&gt;&lt;br /&gt;
Sometimes querying data is not that simple and there may be the need to create temporary tables or views to predefine how the data should look prior to its final output.  Unfortunately there are problems with both of these approaches if you are trying to query data on the fly.  &lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p style="background: white"&gt;&lt;font size="2"&gt;&lt;font face="Verdana"&gt;With the temporary tables approach you need to have multiple steps in your process, first to create the temporary table, then to populate the temporary table, then to select data from the temporary table and lastly cleanup of the temporary table.&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p style="background: white"&gt;&lt;font size="2"&gt;&lt;font face="Verdana"&gt;With the view approach you need to predefine how this data will look, create the view and then use the view in your query.  Granted if this is something that you would be doing over and over again this might make sense to just create a view, but let's look at a totally different approach.&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p style="background: white"&gt;&lt;font size="2"&gt;&lt;font face="Verdana"&gt;&lt;b&gt;&lt;u&gt;Solution&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
With SQL Server you have the ability to create derived tables on the fly and then use these derived tables within your query.  In concept this is similar to creating a temporary table and then using the temporary table in your query, but the approach is much simpler, because it can all be done in one step.&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p style="background: white"&gt;&lt;font size="2"&gt;&lt;font face="Verdana"&gt;Let's take a look at an example where we query the Northwind database to try to find out how many customers fall into various categories based on sales.  The categories that we have predefined are as follows:&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;ul type="disc"&gt;
    &lt;li class="MsoNormal" style="background: white; margin: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l1 level1 lfo1; tab-stops: list .5in"&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;Total Sales between 0 and 5,000 = Micro &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
    &lt;li class="MsoNormal" style="background: white; margin: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l1 level1 lfo1; tab-stops: list .5in"&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;Total Sales between 5,001 and 10,000 = Small &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
    &lt;li class="MsoNormal" style="background: white; margin: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l1 level1 lfo1; tab-stops: list .5in"&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;Total Sales between 10,001 and 15,000 = Medium &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
    &lt;li class="MsoNormal" style="background: white; margin: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l1 level1 lfo1; tab-stops: list .5in"&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;Total Sales between 15,001 and 20,000 = Large &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
    &lt;li class="MsoNormal" style="background: white; margin: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l1 level1 lfo1; tab-stops: list .5in"&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;Total Sales &amp;gt; 20,000 = Very Large&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p style="background: white"&gt;&lt;font size="2"&gt;&lt;font face="Verdana"&gt;There are several ways that this data can be pulled, but let's look at an approach using a derived table.&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p style="background: white"&gt;&lt;font size="2"&gt;&lt;font face="Verdana"&gt;The first step is to find out the total sales by each customer, which can be done with the following statement.&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;div align="center"&gt;
&lt;table class="MsoNormalTable" id="table1" cellspacing="0" cellpadding="0" width="90%" border="1" style="width: 90%; mso-cellspacing: 0in; mso-padding-alt: 2.25pt 2.25pt 2.25pt 2.25pt"&gt;
    &lt;tbody&gt;
        &lt;tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;SELECT   &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;o.CustomerID&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;, &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: gray; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;         &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: fuchsia"&gt;SUM&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;(&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;UnitPrice &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;* &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;Quantity&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;) &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;AS &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;TotalSales &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: black; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;FROM     &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;[Order Details] &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;AS &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;od &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: black; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;         &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;INNER JOIN &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;Orders &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;AS &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;o &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: black; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;           &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;ON &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;od.OrderID &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;= &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;o.OrderID &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: black; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;GROUP BY &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;o.CustomerID&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p style="background: white"&gt;&lt;font size="2"&gt;&lt;font face="Verdana"&gt;This is a partial list of the output:&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;div align="center"&gt;
&lt;table class="MsoNormalTable" id="table2" cellspacing="0" cellpadding="0" border="1" style="mso-cellspacing: 0in; mso-padding-alt: 2.25pt 2.25pt 2.25pt 2.25pt"&gt;
    &lt;tbody&gt;
        &lt;tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes"&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;CustomerID&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;TotalSales&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr style="mso-yfti-irow: 1"&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;CUST1  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;4596.2000&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr style="mso-yfti-irow: 2"&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;CUST2&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;1402.9500&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr style="mso-yfti-irow: 3"&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;CUST3&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;7515.3500&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr style="mso-yfti-irow: 4"&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;...&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr style="mso-yfti-irow: 5; mso-yfti-lastrow: yes"&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;CUSTN&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;3531.9500&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p style="background: white"&gt;&lt;font size="2"&gt;&lt;font face="Verdana"&gt;The next step is to classify the TotalSales value into the OrderGroups that were specified above:&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;div align="center"&gt;
&lt;table class="MsoNormalTable" id="table3" cellspacing="0" cellpadding="0" width="90%" border="1" style="width: 90%; mso-cellspacing: 0in; mso-padding-alt: 2.25pt 2.25pt 2.25pt 2.25pt"&gt;
    &lt;tbody&gt;
        &lt;tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;SELECT   &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;o.CustomerID&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;, &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: gray; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;         &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: fuchsia"&gt;SUM&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;(&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;UnitPrice &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;* &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;Quantity&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;) &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;AS &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;TotalSales&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;, &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: gray; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;         &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: fuchsia"&gt;CASE  &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: fuchsia; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;           &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;WHEN &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: fuchsia"&gt;SUM&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;(&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;UnitPrice &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;* &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;Quantity&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;)  &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: gray; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;               BETWEEN &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;0 &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;AND &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;5000 &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;THEN &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: red"&gt;'Micro' &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: red; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;           &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;WHEN &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: fuchsia"&gt;SUM&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;(&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;UnitPrice &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;* &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;Quantity&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;)  &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: gray; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;               BETWEEN &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;5001 &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;AND &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;10000 &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;THEN &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: red"&gt;'Small' &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: red; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;           &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;WHEN &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: fuchsia"&gt;SUM&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;(&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;UnitPrice &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;* &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;Quantity&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;)  &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: gray; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;               BETWEEN &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;10001 &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;AND &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;15000 &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;THEN &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: red"&gt;'Medium' &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: red; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;           &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;WHEN &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: fuchsia"&gt;SUM&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;(&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;UnitPrice &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;* &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;Quantity&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;)  &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: gray; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;               BETWEEN &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;15001 &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;AND &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;20000 &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;THEN &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: red"&gt;'Large' &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: red; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;           &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;WHEN &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: fuchsia"&gt;SUM&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;(&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;UnitPrice &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;* &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;Quantity&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;)  &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: gray; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;               &amp;gt; &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;20000 &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;THEN &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: red"&gt;'Very Large' &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: red; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;         &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;END AS &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;OrderGroup &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: black; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;FROM     &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;[Order Details] &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;AS &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;od &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: black; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;         &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;INNER JOIN &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;Orders &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;AS &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;o  &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: black; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;          &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;ON &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;od.OrderID &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;= &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;o.OrderID &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: black; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;GROUP BY &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;o.CustomerID&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p style="background: white"&gt;&lt;font size="2"&gt;&lt;font face="Verdana"&gt;This is a partial list of the output:&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;div align="center"&gt;
&lt;table class="MsoNormalTable" id="table4" cellspacing="0" cellpadding="0" border="1" style="mso-cellspacing: 0in; mso-padding-alt: 2.25pt 2.25pt 2.25pt 2.25pt"&gt;
    &lt;tbody&gt;
        &lt;tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes"&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;CustomerID&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;TotalSales&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;OrderGroup&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr style="mso-yfti-irow: 1"&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;CUST1  &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;4596.2000&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;Micro&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr style="mso-yfti-irow: 2"&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;CUST2&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;1402.9500&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;Micro&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr style="mso-yfti-irow: 3"&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;CUST3&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;7515.3500&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;Small&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr style="mso-yfti-irow: 4"&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;...&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr style="mso-yfti-irow: 5; mso-yfti-lastrow: yes"&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;CUSTN&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;3531.9500&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;Micro&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p style="background: white"&gt;&lt;font size="2"&gt;&lt;font face="Verdana"&gt;The next step is to figure out how many customers fit into each of these groups and this is where the derived table comes into play.  Take a look at the following query which uses a derived table called OG.  What we are doing here is using the same query from the step above, but calling this derived table OG. Then we are selecting data from this derived table for our final output just like we would with any other query.  All of the columns that are created in the derived table are now available for our final query.&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;div align="center"&gt;
&lt;table class="MsoNormalTable" id="table5" cellspacing="0" cellpadding="0" width="90%" border="1" style="width: 90%; mso-cellspacing: 0in; mso-padding-alt: 2.25pt 2.25pt 2.25pt 2.25pt"&gt;
    &lt;tbody&gt;
        &lt;tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;SELECT   &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;OG.OrderGroup&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;, &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: gray; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;         &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: fuchsia"&gt;COUNT&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;(&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;OG.OrderGroup&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;) &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;AS &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;OrderGroupCount &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: black; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;FROM     &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;(&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;SELECT   &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;o.CustomerID&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;, &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: gray; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;                   &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: fuchsia"&gt;SUM&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;(&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;UnitPrice &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;* &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;Quantity&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;) &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;AS &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;TotalSales&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;, &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: gray; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;                   &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: fuchsia"&gt;CASE  &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: fuchsia; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;                     &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;WHEN &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: fuchsia"&gt;SUM&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;(&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;UnitPrice &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;* &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;Quantity&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;)  &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: gray; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;                       BETWEEN &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;0 &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;AND &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;5000 &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;THEN &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: red"&gt;'Micro' &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: red; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;                     &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;WHEN &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: fuchsia"&gt;SUM&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;(&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;UnitPrice &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;* &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;Quantity&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;)  &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: gray; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;                       BETWEEN &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;5001 &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;AND &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;10000 &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;THEN &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: red"&gt;'Small' &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: red; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;                     &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;WHEN &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: fuchsia"&gt;SUM&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;(&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;UnitPrice &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;* &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;Quantity&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;)  &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: gray; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;                       BETWEEN &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;10001 &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;AND &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;15000 &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;THEN &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: red"&gt;'Medium' &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: red; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;                     &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;WHEN &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: fuchsia"&gt;SUM&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;(&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;UnitPrice &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;* &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;Quantity&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;)  &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: gray; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;                       BETWEEN &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;15001 &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;AND &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;20000 &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;THEN &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: red"&gt;'Large' &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: red; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;                     &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;WHEN &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: fuchsia"&gt;SUM&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;(&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;UnitPrice &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;* &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;Quantity&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;)  &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: gray; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;                       &amp;gt; &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;20000 &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;THEN &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: red"&gt;'Very Large' &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: red; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;                   &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;END AS &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;OrderGroup &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: black; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;          &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;FROM     &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;[Order Details] &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;AS &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;od &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: black; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;                   &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;INNER JOIN &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;Orders &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;AS &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;o &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: black; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;                     &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;ON &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;od.OrderID &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;= &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;o.OrderID &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: black; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;code&gt;          &lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;GROUP BY &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;o.CustomerID&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: gray"&gt;) &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;AS &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;OG &lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; color: black; font-family: &amp;quot;Courier New&amp;quot;"&gt;&lt;br /&gt;
            &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: blue"&gt;GROUP BY &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="font-size: 10pt; color: black"&gt;OG.OrderGroup&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p style="background: white"&gt;&lt;font size="2"&gt;&lt;font face="Verdana"&gt;This is the complete list of the output from the above query.&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;div align="center"&gt;
&lt;table class="MsoNormalTable" id="table6" cellspacing="0" cellpadding="0" border="1" style="mso-cellspacing: 0in; mso-padding-alt: 2.25pt 2.25pt 2.25pt 2.25pt"&gt;
    &lt;tbody&gt;
        &lt;tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes"&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;OrderGroup&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;OrderGroupCount&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr style="mso-yfti-irow: 1"&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;Large&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;10&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr style="mso-yfti-irow: 2"&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;Medium&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;11&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr style="mso-yfti-irow: 3"&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;Micro&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;33&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr style="mso-yfti-irow: 4"&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;Small&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;15 &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr style="mso-yfti-irow: 5; mso-yfti-lastrow: yes"&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;Very Large&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
            &lt;td valign="top" style="border-right: #d4d0c8; padding-right: 2.25pt; border-top: #d4d0c8; padding-left: 2.25pt; padding-bottom: 2.25pt; border-left: #d4d0c8; padding-top: 2.25pt; border-bottom: #d4d0c8; background-color: transparent"&gt;
            &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: Arial"&gt;20 &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p style="background: white"&gt;&lt;font size="2"&gt;&lt;font face="Verdana"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p style="background: white"&gt;&lt;font size="2"&gt;&lt;font face="Verdana"&gt;&lt;b&gt;&lt;u&gt;Next Steps&lt;/u&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;ul type="disc"&gt;
    &lt;li class="MsoNormal" style="background: white; margin: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l0 level1 lfo2; tab-stops: list .5in"&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;Next time you run into a challenge of whether to create a temporary table or a view to produce the desired query take a look at using a derived table instead &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
    &lt;li class="MsoNormal" style="background: white; margin: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l0 level1 lfo2; tab-stops: list .5in"&gt;&lt;span style="font-size: 10pt; font-family: Verdana"&gt;Experiment with using derived tables, views and temporary tables to see what yields better performance results. There are several articles on the internet that have shown that using a derived table is faster then temporary tables, but try it for yourself. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;font face="Times New Roman" size="3"&gt; &lt;/font&gt;&lt;/o:p&gt;&lt;/p&gt; &lt;img src="http://geekswithblogs.net/Gaurav/aggbug/143431.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Gaurav Taneja</dc:creator>
            <guid>http://geekswithblogs.net/Gaurav/archive/2011/01/10/143431.aspx</guid>
            <pubDate>Tue, 11 Jan 2011 07:15:42 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Gaurav/comments/143431.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Gaurav/archive/2011/01/10/143431.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Gaurav/comments/commentRss/143431.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Gaurav/services/trackbacks/143431.aspx</trackback:ping>
        </item>
        <item>
            <title>Creating a new Job in Sql Step by Step</title>
            <link>http://geekswithblogs.net/Gaurav/archive/2011/01/10/143430.aspx</link>
            <description>&lt;p style="line-height: 16pt"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Trebuchet MS&amp;quot;"&gt;This is about adding a new SQL Jobs in the Sql Server 2005.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h3 style="margin: 3.4pt 0in 0pt; line-height: 16pt"&gt;&lt;span style="font-family: &amp;quot;Trebuchet MS&amp;quot;"&gt;Step 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Trebuchet MS&amp;quot;; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;Make sure that the SQL Server Agent is up and running. You can see it in the taskbar icon. &lt;br style="mso-special-character: line-break" /&gt;
&lt;br style="mso-special-character: line-break" /&gt;
&lt;span style="font-size: 10pt; font-family: &amp;quot;Trebuchet MS&amp;quot;; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;If SQL Server Agent is not running, start it from the SQL Server Configuration Manger&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Trebuchet MS&amp;quot;; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Trebuchet MS&amp;quot;; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;&lt;img height="261" width="292" alt="" src="/images/geekswithblogs_net/Gaurav/Step1.JPG" /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Trebuchet MS&amp;quot;; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Trebuchet MS&amp;quot;; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;
&lt;p style="line-height: 16pt"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Trebuchet MS&amp;quot;"&gt;You can also start the SQL Server Agent from the command prompt using the command netstart &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div style="border-right: #0066cc 3pt solid; padding-right: 3pt; border-top: lightgrey 1pt solid; padding-left: 3pt; background: white; padding-bottom: 3pt; border-left: #0066cc 3pt solid; padding-top: 3pt; border-bottom: lightgrey 1pt solid; mso-border-top-alt: lightgrey .75pt; mso-border-left-alt: #0066CC 3.0pt; mso-border-bottom-alt: lightgrey .75pt; mso-border-right-alt: #0066CC 3.0pt; mso-border-style-alt: solid; mso-element: para-border-div"&gt;
&lt;pre style="background: white; line-height: 16pt"&gt;&lt;span style="font-size: 12pt; color: blue"&gt;net start "SQL Server Agent (&amp;lt;instance name&amp;gt;)"&lt;/span&gt;&lt;span style="font-size: 12pt; color: black"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="background: white; line-height: 16pt"&gt;&lt;span style="font-size: 12pt; color: green"&gt;e.g net start "SQL Server Agent (SQLSERVER01)"&lt;/span&gt;&lt;span style="font-size: 12pt; color: black"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 style="margin: 3.4pt 0in 0pt; line-height: 16pt"&gt;&lt;span style="font-family: &amp;quot;Trebuchet MS&amp;quot;"&gt;Step 2&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Trebuchet MS&amp;quot;; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;Connect to the database engine of SQL server using SQL Server Management Studio. &lt;br style="mso-special-character: line-break" /&gt;
&lt;br style="mso-special-character: line-break" /&gt;
&lt;img height="315" width="416" alt="" src="/images/geekswithblogs_net/Gaurav/Step2.JPG" /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;span style="font-size: 10pt; font-family: &amp;quot;Trebuchet MS&amp;quot;; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;
&lt;h3 style="margin: 3.4pt 0in 0pt; line-height: 16pt"&gt;&lt;span style="font-family: &amp;quot;Trebuchet MS&amp;quot;"&gt;Step 3&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Trebuchet MS&amp;quot;; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;Expand the SQL Server Agent. You will see a Jobs folder over there. Right click on jobs and choose Add New. &lt;br style="mso-special-character: line-break" /&gt;
&lt;br style="mso-special-character: line-break" /&gt;
&lt;img height="363" width="620" alt="" src="/images/geekswithblogs_net/Gaurav/Step3.JPG" /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;span style="font-size: 10pt; font-family: &amp;quot;Trebuchet MS&amp;quot;; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;
&lt;h3 style="margin: 3.4pt 0in 0pt; line-height: 16pt"&gt;&lt;span style="font-family: &amp;quot;Trebuchet MS&amp;quot;"&gt;Step 4&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Trebuchet MS&amp;quot;; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;A New Job popup will appear. Specify the name of the job. &lt;br style="mso-special-character: line-break" /&gt;
&lt;br style="mso-special-character: line-break" /&gt;
&lt;img height="547" width="673" alt="" src="/images/geekswithblogs_net/Gaurav/Step4.JPG" /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;span style="font-size: 10pt; font-family: &amp;quot;Trebuchet MS&amp;quot;; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;
&lt;h3 style="margin: 3.4pt 0in 0pt; line-height: 16pt"&gt;&lt;span style="font-family: &amp;quot;Trebuchet MS&amp;quot;"&gt;Step 5&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Trebuchet MS&amp;quot;; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;Cilck next on the "Steps" in the left menu. A sql job can contain one or more steps. A step might be simply an sql statement or a stored procedure call. Add you step here &lt;br style="mso-special-character: line-break" /&gt;
&lt;br style="mso-special-character: line-break" /&gt;
&lt;img height="632" width="704" alt="" src="/images/geekswithblogs_net/Gaurav/Step5-1.JPG" /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Trebuchet MS&amp;quot;; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Trebuchet MS&amp;quot;; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;Job step added &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Trebuchet MS&amp;quot;; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Trebuchet MS&amp;quot;; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;&lt;img height="632" width="704" alt="" src="/images/geekswithblogs_net/Gaurav/Step5-2.JPG" /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Trebuchet MS&amp;quot;; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Trebuchet MS&amp;quot;; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Trebuchet MS&amp;quot;; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;Cilck next on the "Schedules" in the left menu. A sql job can contain one or more schedules. A schedule is basically the time at which sql job will run it self. You can specify recurring schedules also. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Trebuchet MS&amp;quot;; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Trebuchet MS&amp;quot;; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Trebuchet MS&amp;quot;; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;&lt;img height="583" width="669" alt="" src="/images/geekswithblogs_net/Gaurav/Step5-3.JPG" /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Trebuchet MS&amp;quot;; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Trebuchet MS&amp;quot;; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;Job schedule added &lt;br style="mso-special-character: line-break" /&gt;
&lt;br style="mso-special-character: line-break" /&gt;
&lt;img height="632" width="704" alt="" src="/images/geekswithblogs_net/Gaurav/Step5-4.JPG" /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;span style="font-size: 10pt; font-family: &amp;quot;Trebuchet MS&amp;quot;; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Trebuchet MS&amp;quot;; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;
&lt;p style="line-height: 16pt"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Trebuchet MS&amp;quot;"&gt;You sql job is ready now. However there are other thing you can use if needed like Alert, Notifications etc.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;img src="http://geekswithblogs.net/Gaurav/aggbug/143430.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Gaurav Taneja</dc:creator>
            <guid>http://geekswithblogs.net/Gaurav/archive/2011/01/10/143430.aspx</guid>
            <pubDate>Tue, 11 Jan 2011 07:02:58 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Gaurav/comments/143430.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Gaurav/archive/2011/01/10/143430.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Gaurav/comments/commentRss/143430.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Gaurav/services/trackbacks/143430.aspx</trackback:ping>
        </item>
        <item>
            <title>Truncating All Tables </title>
            <link>http://geekswithblogs.net/Gaurav/archive/2009/06/29/133114.aspx</link>
            <description>&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;
&lt;p&gt;Create&lt;/p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;Procedure&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; GT_DeleteRecords_AllTables&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;
&lt;p&gt;As&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt;
&lt;p&gt;/*********************************************************&lt;/p&gt;
&lt;p&gt;Stored Procedure: GT_DeleteRecords_AllTables&lt;/p&gt;
&lt;p&gt;Do not excute this proc &lt;/p&gt;
&lt;p&gt;Purpose: Delete ALL records within ALL the tables in a DB with ease.&lt;/p&gt;
&lt;p&gt;Test: Exec GT_DeleteRecords_AllTables**********************************************************/&lt;/p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;
&lt;p&gt;Set&lt;/p&gt;
&lt;p&gt;Exec&lt;/p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;nocount&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;on&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#800000" size="2"&gt;&lt;font color="#800000" size="2"&gt;sp_MSForEachTable&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;&lt;font color="#ff0000" size="2"&gt;'Alter Table ? NoCheck Constraint All'&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;
&lt;p&gt;Exec&lt;/p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#800000" size="2"&gt;&lt;font color="#800000" size="2"&gt;sp_MSForEachTable&lt;/font&gt;&lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;&lt;font color="#ff0000" size="2"&gt;
&lt;p&gt;'&lt;/p&gt;
&lt;p&gt;If ObjectProperty(Object_ID(''?''), ''TableHasForeignRef'')=1&lt;/p&gt;
&lt;p&gt;Begin&lt;/p&gt;
&lt;p&gt;-- Just to know what all table used delete syntax.&lt;/p&gt;
&lt;p&gt;Print ''Delete from '' + ''?''&lt;/p&gt;
&lt;p&gt;Delete From ?&lt;/p&gt;
&lt;p&gt;End&lt;/p&gt;
&lt;p&gt;Else&lt;/p&gt;
&lt;p&gt;Begin&lt;/p&gt;
&lt;p&gt;-- Just to know what all table used Truncate syntax.&lt;/p&gt;
&lt;p&gt;Print ''Truncate Table '' + ''?''&lt;/p&gt;
&lt;p&gt;Truncate Table ?&lt;/p&gt;
&lt;p&gt;End&lt;/p&gt;
&lt;p&gt;'&lt;/p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;
&lt;p&gt;Exec&lt;/p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#800000" size="2"&gt;&lt;font color="#800000" size="2"&gt;sp_MSForEachTable&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;&lt;font color="#ff0000" size="2"&gt;'Alter Table ? Check Constraint All'&lt;/font&gt;&lt;/font&gt; &lt;img src="http://geekswithblogs.net/Gaurav/aggbug/133114.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Gaurav Taneja</dc:creator>
            <guid>http://geekswithblogs.net/Gaurav/archive/2009/06/29/133114.aspx</guid>
            <pubDate>Mon, 29 Jun 2009 17:21:30 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Gaurav/comments/133114.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Gaurav/archive/2009/06/29/133114.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Gaurav/comments/commentRss/133114.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Gaurav/services/trackbacks/133114.aspx</trackback:ping>
        </item>
        <item>
            <title>sp_xml_preparedocument</title>
            <link>http://geekswithblogs.net/Gaurav/archive/2008/10/14/125831.aspx</link>
            <description>&lt;p&gt;Example displaying when data is sent in form of xml document&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;  &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  CREATE PROCEDURE XMLINSERT    &lt;br /&gt;
           &lt;br /&gt;
 @intShowVersion   INT  =0,            &lt;br /&gt;
 @strClassName   varchar(250),    &lt;br /&gt;
 @strLang varchar(10),              &lt;br /&gt;
 @strXml text='',    &lt;br /&gt;
 @intError int output    &lt;br /&gt;
     &lt;br /&gt;
          &lt;br /&gt;
AS            &lt;br /&gt;
SET NOCOUNT ON    &lt;br /&gt;
          &lt;br /&gt;
            &lt;br /&gt;
/* @intShowVersion   INTEGER  =0,              &lt;br /&gt;
 @strCreatedBy    VARCHAR(20) = '' ,      &lt;br /&gt;
 @intTemplateID   INTEGER = 0,          &lt;br /&gt;
 @dtClientCreatedOn   DATETIME = '' ,            &lt;br /&gt;
 @strUpdatedBy    VARCHAR(20) = '' ,            &lt;br /&gt;
 @dtClientUpdatedOn   DATETIME  = '' ,    &lt;br /&gt;
 @strXml text='',            &lt;br /&gt;
             &lt;br /&gt;
      &lt;br /&gt;
          &lt;br /&gt;
            &lt;br /&gt;
SET DATEFORMAT dmy            &lt;br /&gt;
             &lt;br /&gt;
IF (@intShowVersion = 1 )            &lt;br /&gt;
 BEGIN            &lt;br /&gt;
  SELECT VERSION='$Revision: 1 $'            &lt;br /&gt;
  RETURN 0            &lt;br /&gt;
 END            &lt;br /&gt;
ELSE            &lt;br /&gt;
 BEGIN            &lt;br /&gt;
  BEGIN TRAN  --Transaction begins            &lt;br /&gt;
  --  DECLARE @intError INTEGER    &lt;br /&gt;
    DECLARE @strDisplayref VARCHAR(200)    &lt;br /&gt;
 DECLARE @intTableId varchar(10)    &lt;br /&gt;
 Declare @StrQuery nvarchar(Max)     &lt;br /&gt;
 Declare @strDelQuery nvarchar(Max)                &lt;br /&gt;
 DECLARE  @hDoc INT    &lt;br /&gt;
 Declare @strTableName nvarchar(100)           &lt;br /&gt;
/*=============================================== START: INSERT INTO [*.Multilingual]==================================================*/            &lt;br /&gt;
       &lt;br /&gt;
    &lt;br /&gt;
EXEC sp_xml_preparedocument  @hDoc OUTPUT,@strXml    &lt;br /&gt;
    &lt;br /&gt;
set @strDisplayref=(select Top 1 CPM.CM_DisplayReference_C from SF_ClassProperty_Master CPM     &lt;br /&gt;
where CPM.CM_ClassIndexId_I =(Select CM.CM_ClassIndexId_I from Sf_Class_Master CM where CM.CM_ClassNAme_C=@strClassName) and CPM.CM_DisplayReference_C is not null )    &lt;br /&gt;
    &lt;br /&gt;
set @strDisplayref= Substring(@strDisplayref,2,Len(@strDisplayref))    &lt;br /&gt;
 print @strDisplayref    &lt;br /&gt;
    &lt;br /&gt;
set @intTableId = (Select CM_TableName_C from sf_class_master where CM_ClassNAme_C=@strClassName)    &lt;br /&gt;
print @intTableId    &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
set @strDisplayref = 'Rowid,[Language],'+ @strDisplayref    &lt;br /&gt;
print @strXml    &lt;br /&gt;
    &lt;br /&gt;
set @strTableName = ''+ @intTableId +'.Multilingual'    &lt;br /&gt;
print @strTableName    &lt;br /&gt;
IF EXISTS (SELECT 1 FROM sysobjects WHERE xtype='u' AND name=''+@strTableName+'')     &lt;br /&gt;
 Begin    &lt;br /&gt;
  set @strDelQuery =N'Delete from ['+ @intTableId +'.Multilingual] where [Language]='''+@strLang+''''    &lt;br /&gt;
  print @strDelQuery    &lt;br /&gt;
  exec sp_executesql @strDelQuery,N'@intTableId varchar,@strLang nvarchar(10)',@intTableId,@strLang    &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  set @strQuery=N' INSERT INTO ['+ @intTableId +'.Multilingual] ('+ @strDisplayref+' )SELECT Rowid,Lang,DisplayRef FROM OPENXML(@hdoc, ''//*/RefValue'',1) WITH(Rowid Int,Lang nvarchar(10),DisplayRef nvarchar(500)) '    &lt;br /&gt;
       &lt;br /&gt;
  print @strquery    &lt;br /&gt;
  exec sp_executesql @strQuery,N'@hdoc int', @hdoc      &lt;br /&gt;
    &lt;br /&gt;
  /*=============================================== END: INSERT INTO [*.Multilingual]==================================================*/            &lt;br /&gt;
    &lt;br /&gt;
  EXEC sp_xml_removedocument @hDoc    &lt;br /&gt;
 End    &lt;br /&gt;
    &lt;br /&gt;
/*=============================================== END:  ==================================================*/            &lt;br /&gt;
  SELECT @intError = @@error     &lt;br /&gt;
  print @intError           &lt;br /&gt;
  IF @intError = 0             &lt;br /&gt;
   BEGIN                 &lt;br /&gt;
    COMMIT TRAN            &lt;br /&gt;
   END              &lt;br /&gt;
  ELSE            &lt;br /&gt;
   BEGIN          &lt;br /&gt;
    ROLLBACK TRAN            &lt;br /&gt;
   END            &lt;br /&gt;
 END        &lt;br /&gt;
    &lt;br /&gt;
SET NOCOUNT OFF &lt;/font&gt;&lt;/p&gt; &lt;img src="http://geekswithblogs.net/Gaurav/aggbug/125831.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Gaurav Taneja</dc:creator>
            <guid>http://geekswithblogs.net/Gaurav/archive/2008/10/14/125831.aspx</guid>
            <pubDate>Tue, 14 Oct 2008 12:17:30 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Gaurav/comments/125831.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Gaurav/archive/2008/10/14/125831.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Gaurav/comments/commentRss/125831.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Gaurav/services/trackbacks/125831.aspx</trackback:ping>
        </item>
        <item>
            <title>Count No of Procedure in Database</title>
            <link>http://geekswithblogs.net/Gaurav/archive/2008/05/05/121919.aspx</link>
            <description>&lt;span style="font-weight: bold;"&gt;Count Procedure&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
select  count(*) from sysobjects where xtype='P'&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;other option is below&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
select CASE(XType) WHEN 'C' THEN 'CHECK constraint'&lt;br /&gt;
WHEN 'D' THEN 'Default or  DEFAULT constraint'&lt;br /&gt;
WHEN 'F' THEN 'FOREIGN KEY constraint'&lt;br /&gt;
WHEN 'L' THEN  'Log'&lt;br /&gt;
WHEN 'FN' THEN 'Scalar function'&lt;br /&gt;
WHEN 'IF' THEN 'Inlined  table-function'&lt;br /&gt;
WHEN 'P' THEN 'Stored procedure'&lt;br /&gt;
WHEN 'PK' THEN 'PRIMARY  KEY constraint (type is K)'&lt;br /&gt;
WHEN 'RF' THEN 'Replication filter stored  procedure' &lt;br /&gt;
WHEN 'S' THEN 'System table'&lt;br /&gt;
WHEN 'TF' THEN 'Table  function'&lt;br /&gt;
WHEN 'TR' THEN 'Trigger'&lt;br /&gt;
WHEN 'U' THEN 'User table'&lt;br /&gt;
WHEN 'UQ'  THEN 'UNIQUE constraint (type is K)'&lt;br /&gt;
WHEN 'V' THEN 'View'&lt;br /&gt;
WHEN 'X' THEN  'Extended stored procedure' END Type&lt;br /&gt;
, Count(*) as total from  sysObjects&lt;br /&gt;
GROUP BY xtype &lt;img src="http://geekswithblogs.net/Gaurav/aggbug/121919.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Gaurav Taneja</dc:creator>
            <guid>http://geekswithblogs.net/Gaurav/archive/2008/05/05/121919.aspx</guid>
            <pubDate>Tue, 06 May 2008 05:02:13 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Gaurav/comments/121919.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Gaurav/archive/2008/05/05/121919.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/Gaurav/comments/commentRss/121919.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Gaurav/services/trackbacks/121919.aspx</trackback:ping>
        </item>
        <item>
            <title>Simple procedure using transaction</title>
            <link>http://geekswithblogs.net/Gaurav/archive/2008/04/06/121097.aspx</link>
            <description>&lt;p&gt;Begin&lt;br /&gt;
        Begin Tran            &lt;br /&gt;
    --Inserting values member details into ServGeneralUser Table&lt;br /&gt;
            Insert into ServGeneralUser(LoginName,Password,Email,Address1,Address2,City,State,OtherStateName,Country,Zip,SecretQuestion,SecretAnswer,Photograph,usertype,updationdate,TnC)&lt;br /&gt;
            values&lt;br /&gt;
            (@LoginName,@Password,@Email,@Address1,@Address2,@City,@State,@OtherState,@Country,@Zip,@SecretQuestion,@SecretAnswer,@Phototgraph,'A',getdate(),'Y')&lt;br /&gt;
            &lt;br /&gt;
    -- reteriving Currently Inserted Members User Id into local variable @userId&lt;br /&gt;
            select @userId=ident_current('ServGeneralUser');            &lt;br /&gt;
    --Inserting values member details into ServMemberDetails Table&lt;br /&gt;
            Insert into ServArtistDetails(Userid,ArtistName,Genre,SubGenre,OfficialWebsite,SignedForCompany,ProffesionalRepresentation,Motto,Influences)&lt;br /&gt;
            values&lt;br /&gt;
            (@userId,@ArtistName,@Genre,@SubGenre,@OffWebSite,@SignedForRecordCompany,@ProfessionalRepresentation,@Motto,@Influences)&lt;br /&gt;
                ----------------------------------------------------&lt;br /&gt;
                declare @Influence varchar(10)&lt;br /&gt;
                        Begin Tran    &lt;br /&gt;
                        set rowcount 0&lt;br /&gt;
                        select * into #mytemp from split(@Influences,',')            &lt;br /&gt;
                        set rowcount 1            &lt;br /&gt;
                        select @Influence = data from #mytemp                        &lt;br /&gt;
                        while @@rowcount &amp;lt;&amp;gt; 0&lt;br /&gt;
                            begin                  &lt;br /&gt;
                               set rowcount 0&lt;br /&gt;
                               delete #mytemp where data = @Influence&lt;br /&gt;
                               set rowcount 1&lt;br /&gt;
                                if(select count(artist_id_7d) from artist_7d where artist_id_7d=@Influence)&amp;lt;=0 &lt;br /&gt;
                                Begin&lt;br /&gt;
                                    set @ErrorCode='ERR2013'&lt;br /&gt;
                                    ROLLBACK TRAN                                        &lt;br /&gt;
                                    select '0' as Result&lt;br /&gt;
                                    return    &lt;br /&gt;
                                End                                    &lt;br /&gt;
                               insert into ServArtistInfluences(UserId,ArtistInfluenceID)values(@userId,@Influence);                                                                                                  &lt;br /&gt;
                               SELECT @intErrorCode = @@ERROR&lt;br /&gt;
                               IF (@intErrorCode &amp;lt;&amp;gt; 0)&lt;br /&gt;
                               Begin&lt;br /&gt;
                                    set @ErrorCode=@intErrorCode                            &lt;br /&gt;
                                    --print 'error occured while inserting record'&lt;br /&gt;
                                    ROLLBACK TRAN&lt;br /&gt;
                                    select '0' as Result                        &lt;br /&gt;
                                    return&lt;br /&gt;
                               End&lt;br /&gt;
                               select @Influence = data from #mytemp&lt;br /&gt;
                            end                    &lt;br /&gt;
                        set rowcount 0&lt;br /&gt;
                        drop table #mytemp    &lt;br /&gt;
                        Commit Tran    &lt;br /&gt;
                        set @ErrorCode='0';&lt;br /&gt;
                        select '1' as Result&lt;br /&gt;
            &lt;br /&gt;
                -----------------------------------------------------&lt;br /&gt;
            set @ErrorCode='0';&lt;br /&gt;
            &lt;br /&gt;
            SELECT @intErrorCode = @@ERROR&lt;br /&gt;
            IF (@intErrorCode &amp;lt;&amp;gt; 0) GOTO PROBLEM&lt;br /&gt;
&lt;br /&gt;
        COMMIT TRAN&lt;br /&gt;
&lt;br /&gt;
        PROBLEM:&lt;br /&gt;
        IF (@intErrorCode &amp;lt;&amp;gt; 0) BEGIN    &lt;br /&gt;
            ROLLBACK TRAN&lt;br /&gt;
        END&lt;br /&gt;
    End&lt;/p&gt; &lt;img src="http://geekswithblogs.net/Gaurav/aggbug/121097.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Gaurav Taneja</dc:creator>
            <guid>http://geekswithblogs.net/Gaurav/archive/2008/04/06/121097.aspx</guid>
            <pubDate>Mon, 07 Apr 2008 11:45:38 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Gaurav/comments/121097.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Gaurav/archive/2008/04/06/121097.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Gaurav/comments/commentRss/121097.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Gaurav/services/trackbacks/121097.aspx</trackback:ping>
        </item>
        <item>
            <title>New in Visual Studio 2008</title>
            <link>http://geekswithblogs.net/Gaurav/archive/2008/04/01/120952.aspx</link>
            <description>&lt;table width="100%" cellspacing="0" cellpadding="0" border="0"&gt;
    &lt;tbody&gt;
        &lt;tr style="font-weight: bold;"&gt;
            &lt;td valign="top" align="left" id="ctl00_ContentPlaceHolder1_tdBlogTitle" class="bluetxt"&gt;What is new in Visual Studio 2008&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt; &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td valign="top" id="ctl00_ContentPlaceHolder1_tdBlogText" class="normaltxt"&gt;
            &lt;p&gt;A quick list of some of the new features are: &lt;/p&gt;
            &lt;ul&gt;
                &lt;li&gt;Multi-Targeting support  &lt;/li&gt;
                &lt;li&gt;Web Designer and CSS support  &lt;/li&gt;
                &lt;li&gt;ASP.NET AJAX and JavaScript support  &lt;/li&gt;
                &lt;li&gt;Project Designer  &lt;/li&gt;
                &lt;li&gt;Data  &lt;/li&gt;
                &lt;li&gt;LINQ – Language Integrated Query &lt;/li&gt;
            &lt;/ul&gt;
            &lt;p&gt;The features listed and explained in this paper are not complete and this  document intends to give you a forehand to start off with VS 2008.&lt;/p&gt;
            &lt;h2 editor_id="mce_editor_0"&gt;&lt;a name="_Toc177808315"&gt;&lt;span class="bluetxt"&gt;&lt;span class="highlight"&gt;&lt;font size="3"&gt;1. Multi-Targeting  Support&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/h2&gt;
            &lt;p&gt;Earlier, each Visual Studio release only supported a specific version of the  .NET Framework. For example, VS 2003 only works with .NET 1.1, and VS 2005 only  works with .NET 2.0. &lt;/p&gt;
            &lt;p&gt;One of the major changes with the VS 2008 release is to support what  Microsoft calls "Multi-Targeting". This means that Visual Studio will now  support targeting multiple versions of the .NET Framework, and developers will  be able to take advantage of the new features that Visual Studio provides  without having to migrate their existing projects and deployed applications to  use a new version of the .NET Framework. &lt;/p&gt;
            &lt;p&gt;Now when we open an existing project or create a new one with VS 2008, we can  pick which version of the .NET Framework to work with. The IDE will update its  compilers and feature-set to match the chosen .NET Framework. &lt;/p&gt;
            &lt;p&gt;Features, controls, projects, item-templates, and references that do not work  with the selected version of the Framework will be made unavailable or will be  hidden. &lt;/p&gt;
            &lt;p&gt;Unfortunately, support has not been included to work with Framework versions  1.1 and earlier. The present release supports 2.0/3.0 and 3.5 .NET Frameworks.  &lt;/p&gt;
            &lt;p&gt;Microsoft plans to continue multi-targeting support in all future releases of  Visual Studio. &lt;/p&gt;
            &lt;h3 editor_id="mce_editor_0"&gt;&lt;span editor_id="mce_editor_0" class="bluetxt"&gt;Creating a New Project with Visual Studio 2008 that  Targets .NET 2.0 Framework Library&lt;/span&gt; &lt;/h3&gt;
            &lt;p&gt;The screenshots below depict the creation of a new web application targeting  .NET 2.0 Framework. Choose File-&amp;gt;New Project. As we see in the snapshot below  in the top-right of the new project dialog, there is now a dropdown that allows  us to choose which versions of the .NET Framework we want to target when we  create the new project. The templates available are filtered depending on the  version of the Framework chosen from the dropdown: &lt;/p&gt;
            &lt;img width="533" height="358" border="0" editor_id="mce_editor_0" src="http://www.codeproject.com/KB/dotnet/Visual_Studio_2008/clip_image002.jpg" alt="" /&gt;
            &lt;h3 editor_id="mce_editor_0"&gt;&lt;span class="bluetxt"&gt;Can I Upgrade an Existing  Project to .NET 3.5?&lt;/span&gt;&lt;/h3&gt;
            &lt;p&gt;When we open a solution created using an older version of Visual Studio and  Framework, VS 2008 would ask if migration is required. If we opt to migrate,  then a migration wizard would start. If we wish to upgrade our project to target  a newer version of the Framework at a later point of time, we can pull up the  project properties page and choose the Target Framework. The required assemblies  are automatically referenced. The snapshot below shows the properties page with  the option Target Framework marked. &lt;/p&gt;
            &lt;img width="597" height="378" border="0" src="http://www.codeproject.com/KB/dotnet/Visual_Studio_2008/clip_image003.gif" alt="" /&gt;
            &lt;h2 editor_id="mce_editor_0"&gt;&lt;span editor_id="mce_editor_0" class="bluetxt"&gt;&lt;span class="highlight"&gt;&lt;font size="3"&gt;2. &lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;a name="_Toc177808315"&gt;&lt;span class="bluetxt"&gt;&lt;span class="highlight"&gt;&lt;font size="3"&gt;Web Designer, Editing and CSS  Support&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/h2&gt;
            &lt;p editor_id="mce_editor_0"&gt;One feature that web developers will discover with  VS 2008 is its drastically improved HTML designer, and the extensive CSS support  made available. &lt;/p&gt;
            &lt;p&gt;The snapshots below depict some of the new web designer features in-built  into VS 2008. &lt;/p&gt;
            &lt;h3 editor_id="mce_editor_0"&gt;&lt;span class="bluetxt"&gt;Split View Editing&lt;/span&gt;&lt;/h3&gt;
            &lt;p&gt;In addition to the existing views, Design view and Code view, VS 2008 brings  along the Split view which allows us to view both the HTML source and the Design  View at the same-time, and easily make changes in any of the views. As shown in  the image below, as we select a tag in code view, the corresponding  elements/controls are selected in design view. &lt;/p&gt;
            &lt;img width="602" height="457" border="0" src="http://www.codeproject.com/KB/dotnet/Visual_Studio_2008/clip_image004.gif" alt="" /&gt;
            &lt;h3 editor_id="mce_editor_0"&gt;&lt;span class="bluetxt"&gt;CSS Style Manager&lt;/span&gt;&lt;/h3&gt;
            &lt;p&gt;VS 2008 introduces a new tool inside the IDE called "Manage Styles". This  shows all of the CSS style sheets for the page. &lt;/p&gt;
            &lt;p&gt;It can be used when we are in any of the views - design, code and split  views. Manage Styles tool can be activated by choosing Format -&amp;gt; CSS Styles  -&amp;gt; Manage Styles from the menu. A snapshot of the same would look like the  following: &lt;/p&gt;
            &lt;img width="602" height="338" border="0" src="http://www.codeproject.com/KB/dotnet/Visual_Studio_2008/clip_image005.gif" alt="" /&gt;
            &lt;p&gt;Create a new style using the new style dialog window as show in the snapshot  below.&lt;/p&gt;
            &lt;img width="340" height="325" border="0" src="http://www.codeproject.com/KB/dotnet/Visual_Studio_2008/clip_image006.jpg" alt="" /&gt;
            &lt;p&gt;Now, the style manager would show &lt;code&gt;.labelcaption&lt;/code&gt; style as well in  the CSS styles list. However, if we observe that the body element has a circle  around it but the &lt;code&gt;.labelcaption&lt;/code&gt; does not have one, this is because  the style is not in use yet. &lt;/p&gt;
            &lt;img width="544" height="359" border="0" src="http://www.codeproject.com/KB/dotnet/Visual_Studio_2008/clip_image007.jpg" alt="" /&gt;
            &lt;p&gt;We will not select all the labels below and apply our new style  &lt;code&gt;.labelcaption&lt;/code&gt;.&lt;/p&gt;
            &lt;img width="537" height="344" border="0" src="http://www.codeproject.com/KB/dotnet/Visual_Studio_2008/clip_image008.jpg" alt="" /&gt;
            &lt;p&gt;We can choose to modify the existing style through GUI using "Modify  style..." menu option in the dropdown menu as shown above or choose to hand edit  the code by choosing the option "Go To Code". &lt;/p&gt;
            &lt;h3 editor_id="mce_editor_0"&gt;&lt;span class="bluetxt"&gt;CSS Source View  Intellisense&lt;/span&gt;&lt;/h3&gt;
            &lt;p&gt;The designer is equipped with the ability to select an element or control in  design-view, and graphically select a rule from the CSS list to apply to it.  &lt;/p&gt;
            &lt;p&gt;We will also find when in source mode that we now have intellisense support  for specifying CSS class rules. The CSS Intellisense is supported in both  regular ASP.NET pages as well as when working with pages based on master pages.  &lt;/p&gt;
            &lt;img width="499" height="402" border="0" src="http://www.codeproject.com/KB/dotnet/Visual_Studio_2008/clip_image009.jpg" alt="" /&gt;
            &lt;h3 editor_id="mce_editor_0"&gt;&lt;span class="bluetxt"&gt;Code Editing  Enhancements&lt;/span&gt;&lt;/h3&gt;
            &lt;p&gt;Below is a non-exhaustive list of a few new code editing improvements. There  are many more about which I don't know yet. &lt;/p&gt;
            &lt;h4 editor_id="mce_editor_0"&gt;&lt;span class="bluetxt"&gt;Transparent Intellisense  Mode&lt;/span&gt; &lt;/h4&gt;
            &lt;p&gt;While using VS 2005/2003 we often find ourselves escaping out of intellisense  in order to better see the code around, and then go back and complete what we  were doing. &lt;/p&gt;
            &lt;p&gt;VS 2008 provides a new feature which allows us to quickly make the  intellisense drop-down list semi-transparent. Just hold down the "Ctrl" key  while the intellisense drop-down is visible and we will be able to switch it  into a transparent mode that enables us to look at the code beneath without  having to escape out of Intellisense. The screenshot below depicts the same.  &lt;/p&gt;
            &lt;img width="554" height="298" border="0" src="http://www.codeproject.com/KB/dotnet/Visual_Studio_2008/clip_image0010.gif" alt="" /&gt;
            &lt;h4 editor_id="mce_editor_0"&gt;&lt;span class="bluetxt"&gt;Organize C# Using  Statements&lt;/span&gt; &lt;/h4&gt;
            &lt;p&gt;One of the small, but a nice new feature in VS 2008 is support for better  organizing &lt;code&gt;&lt;span class="code-keyword"&gt;using&lt;/span&gt;&lt;/code&gt; statements in C#.  We can now select a list of &lt;code&gt;&lt;span class="code-keyword"&gt;using&lt;/span&gt;&lt;/code&gt;  statements, right-click, and then select the "Organize Usings" sub-menu. When we  use this command the IDE will analyze what types are used in the code file, and  will automatically remove those namespaces that are declared but not required. A  small and handy feature for code refactoring. &lt;/p&gt;
            &lt;img width="476" height="347" border="0" src="http://www.codeproject.com/KB/dotnet/Visual_Studio_2008/clip_image0011.jpg" alt="" /&gt;
            &lt;h2 editor_id="mce_editor_0"&gt;&lt;span class="highlight"&gt;&lt;font size="3" editor_id="mce_editor_0"&gt;3. &lt;/font&gt;&lt;/span&gt;&lt;a name="_Toc177808314"&gt;&lt;span class="highlight"&gt;&lt;font size="3"&gt;ASP.NET &lt;/font&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class="highlight"&gt;&lt;font size="3"&gt;AJAX and JavaScript Support&lt;/font&gt;&lt;/span&gt;&lt;/h2&gt;
            &lt;h3 editor_id="mce_editor_0"&gt;&lt;span class="bluetxt"&gt;JavaScript  Intellisense&lt;/span&gt;&lt;/h3&gt;
            &lt;p&gt;One new feature that developers will find with VS 2008 is its built-in  support for JavaScript Intellisense. This makes using JavaScript and building  AJAX applications significantly easier. A double click on HTML control in design  mode would automatically create a click event to the button and would create the  basic skeleton of the JavaScript function. As we see in the depicted image  below, JavaScript Intellisense is inbuilt now. Other JavaScript Intellisense  features include Intellisense for external JavaScript libraries and adding  Intellisense hints to JavaScript functions. &lt;/p&gt;
            &lt;img width="441" height="297" border="0" src="http://www.codeproject.com/KB/dotnet/Visual_Studio_2008/clip_image0012.jpg" alt="" /&gt;
            &lt;h3 editor_id="mce_editor_0"&gt;&lt;span class="bluetxt"&gt;JavaScript  Debugging&lt;/span&gt;&lt;/h3&gt;
            &lt;p&gt;One new JavaScript feature in VS 2008 is the much-improved support for  JavaScript debugging. This makes debugging AJAX applications significantly  easier. JavaScript debugging was made available in VS 2005 itself. However, we  had to run the web application first to set the breakpoint or use the "debugger"  JavaScript statement. &lt;/p&gt;
            &lt;p&gt;VS 2008 makes this much better by adding new support that allows us to set  client-side JavaScript breakpoints directly within your server-side  &lt;em&gt;.aspx&lt;/em&gt; and &lt;em&gt;.master&lt;/em&gt; source files. &lt;/p&gt;
            &lt;p&gt;We can now set both client-side JavaScript breakpoints and VB/C# server-side  breakpoints at the same time on the same page and use a single debugger to step  through both the server-side and client-side code in a single debug session.  This feature is extremely useful for AJAX applications. The breakpoints are  fully supported in external JavaScript libraries as well. &lt;/p&gt;
            &lt;h2 editor_id="mce_editor_0"&gt;&lt;span class="highlight"&gt;&lt;font size="3"&gt;4.  &lt;/font&gt;&lt;/span&gt;&lt;a name="_Toc177808315"&gt;&lt;span class="highlight"&gt;&lt;font size="3"&gt;Few Other  Features and Enhancements&lt;/font&gt;&lt;/span&gt;&lt;/a&gt;&lt;/h2&gt;
            &lt;p&gt;Below is a list of few other enhancements and new features included in  Microsoft Visual Studio 2008. &lt;/p&gt;
            &lt;h3 editor_id="mce_editor_0"&gt;&lt;span class="bluetxt"&gt;Project Designer&lt;/span&gt;&lt;/h3&gt;
            &lt;p&gt;Windows Presentation Foundation (WPF) applications have been added to Visual  Studio 2008. There are four WPF project types: &lt;/p&gt;
            &lt;ul&gt;
                &lt;li&gt;WinFX Windows Application  &lt;/li&gt;
                &lt;li&gt;WinFX Web Browser Application  &lt;/li&gt;
                &lt;li&gt;WinFX Custom Control Library  &lt;/li&gt;
                &lt;li&gt;WinFX Service Library &lt;/li&gt;
            &lt;/ul&gt;
            &lt;p&gt;When a WPF project is loaded in the IDE, the user interface of the Project  Designer pages lets us specify properties specific to WPF applications. &lt;/p&gt;
            &lt;h3&gt;&lt;span class="bluetxt"&gt;Data&lt;/span&gt;&lt;/h3&gt;
            &lt;p&gt;&lt;a name="data"&gt;Microsoft Visual Studio 2008 Beta 2 includes the following new  features to incorporate data into applications: &lt;/a&gt;&lt;/p&gt;
            &lt;ul&gt;
                &lt;li&gt;The Object Relational Designer (O/R Designer) assists developers in creating  and editing the objects (LINQ to SQL entities) that map between an application  and a remote database  &lt;/li&gt;
                &lt;li&gt;Hierarchical update capabilities in Dataset Designer, providing generated  code that includes the save logic required to maintain referential integrity  between related tables  &lt;/li&gt;
                &lt;li&gt;Local database caching incorporates an SQL Server Compact 3.5 database into  an application and configures it to periodically synchronize the data with a  remote database on a server. Local database caching enables applications to  reduce the number of round trips between the application and a database server  &lt;/li&gt;
            &lt;/ul&gt;
            &lt;h3 editor_id="mce_editor_0"&gt;&lt;span class="highlight"&gt;&lt;span class="bluetxt"&gt;LINQ –  Language Integrated Query&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
            &lt;p editor_id="mce_editor_0"&gt;LINQ is a new feature in VS 2008 that broadens great  querying capabilities into the language syntax. LINQ introduces patterns for  querying and updating data. A set of new assemblies are provided that enable the  use of LINQ with collections, SQL databases, and XML documents. &lt;/p&gt;
            &lt;h3 editor_id="mce_editor_0"&gt;&lt;span editor_id="mce_editor_0" class="highlight"&gt;&lt;span class="bluetxt"&gt;Visual Studio 2008  Debugger&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
            &lt;p&gt;The Visual Studio 2008 debugger has been enhanced with the following  features: &lt;/p&gt;
            &lt;ul&gt;
                &lt;li&gt;Remote debugging support on Windows Vista  &lt;/li&gt;
                &lt;li&gt;Improved support for debugging multithreaded applications  &lt;/li&gt;
                &lt;li&gt;Debugging support for LINQ programming  &lt;/li&gt;
                &lt;li&gt;Debugging support for Windows Communications Foundation  &lt;/li&gt;
                &lt;li&gt;Support for script debugging, including client-side script files generated  from server-side script now appear in Solution Explorer &lt;/li&gt;
            &lt;/ul&gt;
            &lt;h3 editor_id="mce_editor_0"&gt;&lt;span editor_id="mce_editor_0" class="highlight"&gt;&lt;span class="bluetxt"&gt;Reporting&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
            &lt;p&gt;Visual Studio 2008 provides several new reporting features and improvements  such as: &lt;/p&gt;
            &lt;ul&gt;
                &lt;li&gt;New Report Projects: Visual Studio 2008 includes two new project templates  for creating reporting applications. When we create a new Reports Application  project, Visual Studio provides a report (&lt;em&gt;.rdlc&lt;/em&gt;) and a form with a  ReportViewer control bound to the report.  &lt;/li&gt;
                &lt;li&gt;Report Wizard: Visual Studio 2008 introduces a Report Wizard, which guides  us through the steps to create a basic report. After we complete the wizard, we  can enhance the report by using Report Designer.  &lt;/li&gt;
                &lt;li&gt;Expression Editor Enhancement: The Expression Editor now provides  expressions that we can use directly or customize as required.  &lt;/li&gt;
                &lt;li&gt;PDF Compression: The ReportViewer controls can now compress reports that are  rendered or exported to the PDF format. &lt;/li&gt;
            &lt;/ul&gt;
            &lt;br /&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt; &lt;img src="http://geekswithblogs.net/Gaurav/aggbug/120952.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Gaurav Taneja</dc:creator>
            <guid>http://geekswithblogs.net/Gaurav/archive/2008/04/01/120952.aspx</guid>
            <pubDate>Wed, 02 Apr 2008 11:27:16 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Gaurav/comments/120952.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Gaurav/archive/2008/04/01/120952.aspx#feedback</comments>
            <slash:comments>4</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/Gaurav/comments/commentRss/120952.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Gaurav/services/trackbacks/120952.aspx</trackback:ping>
        </item>
        <item>
            <title>Function to convert DateTime to MM/DD/YYYY format  + SQL SERVER</title>
            <link>http://geekswithblogs.net/Gaurav/archive/2008/04/01/120949.aspx</link>
            <description>&lt;span style="font-weight: bold;"&gt;Function to convert DateTime to MM/DD/YYYY format&lt;/span&gt;&lt;br style="font-weight: bold;" /&gt;
&lt;br /&gt;
CreateFUNCTION [dbo].[tkfunConvertDateToMMDDYYYY](@dtDate varchar(10))&lt;br /&gt;
    RETURNS VARCHAR(10)&lt;br /&gt;
AS&lt;br /&gt;
BEGIN&lt;br /&gt;
    RETURN substring(@dtDate,4,2)+'/'+substring(@dtDate,1,2)+'/'+substring(@dtDate,7,4)&lt;br /&gt;
END &lt;img src="http://geekswithblogs.net/Gaurav/aggbug/120949.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Gaurav Taneja</dc:creator>
            <guid>http://geekswithblogs.net/Gaurav/archive/2008/04/01/120949.aspx</guid>
            <pubDate>Wed, 02 Apr 2008 09:41:35 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Gaurav/comments/120949.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Gaurav/archive/2008/04/01/120949.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Gaurav/comments/commentRss/120949.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Gaurav/services/trackbacks/120949.aspx</trackback:ping>
        </item>
        <item>
            <title>Function to Convert DateTime to DD/MM/YYYY format + SQL SERVER</title>
            <link>http://geekswithblogs.net/Gaurav/archive/2008/04/01/120948.aspx</link>
            <description>&lt;span style="font-weight: bold;"&gt;Function to Convert DateTime to DD/MM/YYYY format&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
CreateFUNCTION [dbo].[tkfunConvertDateToDDMMYYYY](@dtDate varchar(10))&lt;br /&gt;
    RETURNS datetime&lt;br /&gt;
AS&lt;br /&gt;
BEGIN&lt;br /&gt;
    RETURN Convert(datetime,substring(@dtDate,4,2)+'/'+substring(@dtDate,1,2)+'/'+substring(@dtDate,7,4))&lt;br /&gt;
END &lt;img src="http://geekswithblogs.net/Gaurav/aggbug/120948.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Gaurav Taneja</dc:creator>
            <guid>http://geekswithblogs.net/Gaurav/archive/2008/04/01/120948.aspx</guid>
            <pubDate>Wed, 02 Apr 2008 09:40:15 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Gaurav/comments/120948.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Gaurav/archive/2008/04/01/120948.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/Gaurav/comments/commentRss/120948.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Gaurav/services/trackbacks/120948.aspx</trackback:ping>
        </item>
        <item>
            <title>Remove Special Character from XML string + sql Server</title>
            <link>http://geekswithblogs.net/Gaurav/archive/2008/04/01/120947.aspx</link>
            <description>&lt;span style="font-weight: bold;"&gt;Remove Special Character from string &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
-- =============================================&lt;br /&gt;
-- Author:        &amp;lt;Author,,Name&amp;gt;&lt;br /&gt;
-- Create date: &amp;lt;Create Date, ,&amp;gt;&lt;br /&gt;
-- Description:    &amp;lt;Description, ,&amp;gt;&lt;br /&gt;
-- =============================================&lt;br /&gt;
ALTER  FUNCTION [dbo].[RemoveSpChar]&lt;br /&gt;
(&lt;br /&gt;
    -- Add the parameters for the function here&lt;br /&gt;
    @sInput varchar(MAX)=''&lt;br /&gt;
)&lt;br /&gt;
RETURNS varchar(MAX)&lt;br /&gt;
AS&lt;br /&gt;
BEGIN&lt;br /&gt;
    -- Declare the return variable here&lt;br /&gt;
    DECLARE @sOutput Varchar(MAX),&lt;br /&gt;
            @iIndex int,&lt;br /&gt;
            @iLength int,&lt;br /&gt;
            @sChar varchar(1),&lt;br /&gt;
            @iASCII int,&lt;br /&gt;
            @iLen int,&lt;br /&gt;
            @iRem int&lt;br /&gt;
&lt;br /&gt;
    set @sInput= ltrim(rtrim(@sInput))&lt;br /&gt;
    set @iLength = len(@sInput)&lt;br /&gt;
    set @iIndex =1&lt;br /&gt;
    set @sOutput=''&lt;br /&gt;
&lt;br /&gt;
    while @iIndex &amp;lt;= @iLength&lt;br /&gt;
    begin&lt;br /&gt;
        set @sChar=substring(@sInput,@iIndex,1)&lt;br /&gt;
        set @iASCII=ascii(@sChar)&lt;br /&gt;
        &lt;br /&gt;
        if ((@iASCII&amp;gt;=48 and @iASCII&amp;lt;=57) or (@iASCII&amp;gt;=65 and @iASCII&amp;lt;=90) or (@iASCII&amp;gt;=97 and @iASCII&amp;lt;=122) )&lt;br /&gt;
            set @sOutput=@sOutput+@sChar&lt;br /&gt;
            --return @sChar + ' - ' + convert(varchar,@iASCII)&lt;br /&gt;
        set @iIndex =@iIndex +1&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    if len(@sOutput)&amp;gt;17&lt;br /&gt;
        set @sOutput=substring(@sOutput,1,17)&lt;br /&gt;
    else if len(@sOutput)&amp;lt;6&lt;br /&gt;
    begin&lt;br /&gt;
        set @iLen=len(@sOutput)&lt;br /&gt;
        set @iRem=6-@iLen&lt;br /&gt;
        &lt;br /&gt;
        set @sOutput=substring(@sOutput + replicate('0',@iRem),1,6)&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    -- Return the result of the function&lt;br /&gt;
    RETURN @sOutput&lt;br /&gt;
&lt;br /&gt;
END &lt;img src="http://geekswithblogs.net/Gaurav/aggbug/120947.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Gaurav Taneja</dc:creator>
            <guid>http://geekswithblogs.net/Gaurav/archive/2008/04/01/120947.aspx</guid>
            <pubDate>Wed, 02 Apr 2008 09:38:18 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Gaurav/comments/120947.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Gaurav/archive/2008/04/01/120947.aspx#feedback</comments>
            <slash:comments>3</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/Gaurav/comments/commentRss/120947.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Gaurav/services/trackbacks/120947.aspx</trackback:ping>
        </item>
    </channel>
</rss>
