<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Dave does Data</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/davidlean/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/davidlean/feed.xml</link>
    <description>Tutorials, Performance Tuning, Tips &amp;amp; Techniques on SQL Server &amp;amp; its ecosystem.</description>
    <lastBuildDate>Tue, 31 Mar 2015 17:01:07 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>TSQL Tips: Writing more efficient DDL (Data Definition Language) with system functions</title>
      <link>https://docs.microsoft.com/archive/blogs/davidlean/tsql-tips-writing-more-efficient-ddl-data-definition-language-with-system-functions</link>
      <pubDate>Sun, 28 Nov 2010 23:36:55 GMT</pubDate>
      <dc:creator><![CDATA[davele]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/davidlean/2010/11/28/tsql-tips-writing-more-efficient-ddl-data-definition-language-with-system-functions/</guid>
      <description><![CDATA[&#160;  The internet is swimming with examples of really inefficient TSQL code. Just because...]]></description>
      <content:encoded><![CDATA[<p>&#160;</p>  <p>The internet is swimming with examples of really inefficient TSQL code. Just because everyone does it that way doesn’t make it optimal. I’ve already blogged about the issues you will find with <a title="Don&#39;t do it." href="https://blogs.msdn.com/b/davidlean/archive/2009/04/06/sql-server-nolock-hint-other-poor-ideas.aspx" target="_blank">NOLOCK hints</a>, this post show that using system functions correctly can result in your Data Definition Language (DDL) running 3 times faster. </p>  <h2><u><em>Example 1: Faster way to check existence of a table (object)</em></u></h2>  <br />  <h4>Common but Slowest</h4>  <p>If you Right Click on a Table in SQL”s Management Studio you may enjoy the benefits of “Script Table As…”. Among other options it lets you create a script to “DROP AND CREATE”. It will generate a script similar to </p>  <pre class="code"><span style="color: green">-- Common Style of DML Check, then Drop &amp; Create a table.
</span><span style="color: blue">IF </span><span style="color: gray">NOT EXISTS ( </span><span style="color: blue">SELECT </span><span style="color: gray">* 
                </span><span style="color: blue">FROM </span><span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">objects
                </span><span style="color: blue">WHERE </span><span style="color: magenta">object_id </span><span style="color: gray">= </span><span style="color: magenta">OBJECT_ID</span><span style="color: gray">(</span><span style="color: red">N'dbo.MyTable'</span><span style="color: gray">)
                AND </span><span style="color: blue">type </span><span style="color: gray">IN (</span><span style="color: red">N'U'</span><span style="color: gray">)
               ) 
</span><span style="color: blue">CREATE TABLE </span>dbo<span style="color: gray">.</span>MyTable<span style="color: gray">(</span>Rep_ID <span style="color: blue">INT </span><span style="color: gray">Null) </span></pre>

<p>For this discussion I’d draw your attention to the TSQL that searches for existence of the user table ie: </p>

<pre class="code"><span style="color: green">-- Popular Approach
    </span><span style="color: blue">SELECT </span><span style="color: gray">* 
    </span><span style="color: blue">FROM </span><span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">objects 
    </span><span style="color: blue">WHERE </span><span style="color: magenta">object_id </span><span style="color: gray">= </span><span style="color: magenta">OBJECT_ID</span><span style="color: gray">(</span><span style="color: red">N'dbo.MyTable'</span><span style="color: gray">) AND </span><span style="color: blue">type </span><span style="color: gray">IN (</span><span style="color: red">N'U'</span><span style="color: gray">)</span></pre>

<h4>Better use of System function &amp; faster</h4>

<p>A quick read of SQL’s Books Online will make you aware that the SQL Function OBJECT_ID() has a 2nd parameter that lets you specify the type of the object you are searching for. If you use it, you will find that your query runs twice as fast. Why? There was no need to test the condition on the Type column separately. </p>

<pre class="code"><span style="color: green">-- Better: Use the 2nd Parameter instead of an AND&#160;&#160; - Same results but neater
    </span><span style="color: blue">SELECT </span><span style="color: gray">* 
    </span><span style="color: blue">FROM </span><span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">objects 
    </span><span style="color: blue">WHERE </span><span style="color: magenta">object_id </span><span style="color: gray">= </span><span style="color: magenta">OBJECT_ID</span><span style="color: gray">(</span><span style="color: red">N'dbo.MyTable'</span><span style="color: gray">, </span><span style="color: red">N'U'</span><span style="color: gray">)</span></pre>


<p>You may have read that “SELECT *” was inefficient &amp; you should always specify the columns you need. That is very true, in most circumstances. The exception to the rule is when the select is part of the “EXISTS” clause as it is here. In this case, the SQL Optimiser is smart enough to know that it only needs to know if a row is returned &amp; doesn’t care about any of the columns in the select list. So performance in the following alternative is exactly the same. Use whatever you prefer, either alternative is slower than the last alternative.&#160;&#160; <pre class="code"><span style="color: green">-- Better: Use the 2nd Parameter instead of an AND&#160;&#160; - Same speed as SELECT *
    </span><span style="color: blue">SELECT </span>1 
    <span style="color: blue">FROM </span><span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">objects 
    </span><span style="color: blue">WHERE </span><span style="color: magenta">object_id </span><span style="color: gray">= </span><span style="color: magenta">OBJECT_ID</span><span style="color: gray">(</span><span style="color: red">N'dbo.MyTable'</span><span style="color: gray">, </span><span style="color: red">N'U'</span><span style="color: gray">)</span></pre>
  </p>


<h4>Fastest</h4>

<p>As the OBJECT_ID() function can be used in all TSQL, there is no need to wrap it up in a SELECT statement. It returns NULL if the object is not found so just compare its output to NULL. e.g:
  <pre class="code"><span style="color: green">-- Faster: just use the function &amp; 2nd parameter - 3 Times faster
    </span><span style="color: blue">IF </span><span style="color: magenta">OBJECT_ID</span><span style="color: gray">(</span><span style="color: red">N'dbo.MyTable'</span><span style="color: gray">, </span><span style="color: red">N'U'</span><span style="color: gray">) IS NOT NULL
        </span><span style="color: blue">CREATE TABLE </span>dbo<span style="color: gray">.</span>MyTable<span style="color: gray">(</span>Rep_ID <span style="color: blue">INT </span><span style="color: gray">Null)
</span><span style="color: green">--Only save millisecs here but same applies with any IF EXISTS which could be way more expensive. (Use an index instead of table scan etc.)</span></pre>
  </p>

<p>Not only is this is 3 times faster. It means less code, so less chance of making errors. Most importantly it avoids the bad (&amp; unsupported) practice if querying the system tables directly (in this case sys.objects). </p>

<p>In case you haven’t heard, you should be using the Informational Schema Views &amp; System Functions instead of the system tables because Microsoft may change the system tables between releases which will break all your code. Yes I know “everyone” does it. Yes I am a hypocrite as many of my tuning tools are very vulnerable to System Table changes. But Microsoft was saying this from Version 1.1 (in 1990) they never changed &amp; DBA’s got blasé about it. But 15 years later with the release of SQL 2005 we found sysobjects became sys.objects. While they did a great job of backward compatibility it does highlight the risk you take using System Tables in the heart of your application. </p>

<h4>Post thought</h4>

<p>You might wonder “why didn’t the SQL Server Management Studio doesn’t produce a better example of code. Surely they know how”. The tools team were likely to have a different goal to you. They were writing a context menu function that worked anywhere in the Object Explorer tree; Tables, Views, Functions Indexes etc. While many of these objects can be handled by OBJECT_ID(), some can’t. So it is more expedient to write a generic routine what worked everywhere than to produce optimal code samples with heaps of special case code. Especially when in this case the % improvement my be huge, but the actual time saved is still measured in millisecs, so who cares. </p>

<p>This blog is about the concept of system functions. And for some queries it makes a huge difference.</p>

<h2><em><u>Example 2: Faster way find indexes on User Tables.</u></em></h2>

<br />

<p>Perhaps you want to see all the Indexes in your system but don’t want the results cluttered with indexes on the System Catalog. Unfortunately when you query the Sys.Indexes table it doesn’t tell you if the Index is on a User Table, a System Table or an Indexed View. So you find yourself frequently joining on the Sys.Objects table &amp; filtering with Type = N’U’ eg: </p>

<pre class="code"><span style="color: green">-- 2 table join to filter on User Tables.
</span><span style="color: blue">SELECT  </span><span style="color: magenta">OBJECT_SCHEMA_NAME</span><span style="color: gray">(</span>I<span style="color: gray">.</span><span style="color: magenta">object_id</span><span style="color: gray">) </span><span style="color: blue">AS </span>[Schema]<span style="color: gray">,
        </span><span style="color: magenta">OBJECT_NAME</span><span style="color: gray">(</span>I<span style="color: gray">.</span><span style="color: magenta">object_id</span><span style="color: gray">) </span><span style="color: blue">AS </span>[Table]<span style="color: gray">,
        </span>I<span style="color: gray">.* 
</span><span style="color: blue">FROM </span><span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">indexes </span><span style="color: blue">AS </span>I
<span style="color: gray">JOIN </span><span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">objects </span><span style="color: blue">AS </span>O <span style="color: blue">ON </span>O<span style="color: gray">.</span><span style="color: magenta">object_id </span><span style="color: gray">= </span>I<span style="color: gray">.</span><span style="color: magenta">object_id
</span><span style="color: blue">WHERE </span>O<span style="color: gray">.</span><span style="color: blue">type </span><span style="color: gray">= </span><span style="color: red">'U'</span></pre>

<p>Often I’ve found that I needed to think about indexes on Indexes views too. So it was better just to filter out all system objects than to limit my query to User Tables. So the query changes to :-</p>

<pre class="code"><span style="color: green">-- 2 table join to filter out System Objects.
</span><span style="color: blue">SELECT  </span><span style="color: magenta">OBJECT_SCHEMA_NAME</span><span style="color: gray">(</span>I<span style="color: gray">.</span><span style="color: magenta">object_id</span><span style="color: gray">) </span><span style="color: blue">AS </span>[Schema]<span style="color: gray">,
        </span><span style="color: magenta">OBJECT_NAME</span><span style="color: gray">(</span>I<span style="color: gray">.</span><span style="color: magenta">object_id</span><span style="color: gray">) </span><span style="color: blue">AS </span>[Table]<span style="color: gray">,
        </span>I<span style="color: gray">.* 
</span><span style="color: blue">FROM </span><span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">indexes </span><span style="color: blue">AS </span>I
<span style="color: gray">JOIN </span><span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">objects </span><span style="color: blue">AS </span>O <span style="color: blue">ON </span>O<span style="color: gray">.</span><span style="color: magenta">object_id </span><span style="color: gray">= </span>I<span style="color: gray">.</span><span style="color: magenta">object_id
</span><span style="color: blue">WHERE </span>O<span style="color: gray">.</span><span style="color: magenta">schema_id </span><span style="color: gray">&lt;&gt; </span>4</pre>

<p>But as I only wanted to filter the System Objects out of the Sys.Indexes Table I didn’t need the join with sys.objects at all. As I have the Object_ID I could use OBJECT_ID() or OBJECT_SCHEMA_NAME() to remove rows I didn’t like. eg:</p>

<pre class="code"><span style="color: green">-- Single table scan, Filtered by System Function, nearly 4 times faster.
</span><span style="color: blue">SELECT  </span><span style="color: magenta">OBJECT_SCHEMA_NAME</span><span style="color: gray">(</span>I<span style="color: gray">.</span><span style="color: magenta">object_id</span><span style="color: gray">) </span><span style="color: blue">AS </span>[Schema]<span style="color: gray">,
        </span><span style="color: magenta">OBJECT_NAME</span><span style="color: gray">(</span>I<span style="color: gray">.</span><span style="color: magenta">object_id</span><span style="color: gray">) </span><span style="color: blue">AS </span>[Table]<span style="color: gray">,
        </span>I<span style="color: gray">.* 
</span><span style="color: blue">FROM </span><span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">indexes </span><span style="color: blue">AS </span>I
<span style="color: blue">WHERE </span><span style="color: magenta">OBJECT_SCHEMA_NAME</span><span style="color: gray">(</span>I<span style="color: gray">.</span><span style="color: magenta">object_id</span><span style="color: gray">) &lt;&gt; </span><span style="color: red">'sys'
</span><span style="color: blue">go</span></pre>

<p>Its nearly 4 times faster, &amp; less code to write. Of course if you still want to filter for User Tables the OBJECT_ID() function will work as I showed in Example 1. </p>

<p>This approach is especially handy when working with Dynamic Management Views which I’ll show in a future post. </p>

<p>Hope this encourages you to read up on some of the other SQL System functions. </p>

<p>Dave</p>

<p>&#160;</p>

<h6>Thought for the Post</h6>

<p>OMG (Oh! My God) is an expression that seems to be everywhere these days. But I wonder if I could read Arabic, do they type OMA (Oh! My Allah) or is the term God sufficiently generic? Will we start seeing OMB for those who follow Buddha. OMJ (Oh! My Jehovah), OMI (Oh! My Infinity) for the Scientologists. etc</p>

<p>If someone says “Oh! My” are they an Atheist or just too lazy to mention the omnipotent super-being of their choice.</p>

<p>I assume that an Antagonist would type OYG (Oh! your God!) or perhaps OME (Oh! My Ex-god). </p>

<p>It was so much easier when people used four letter words to express themselves. </p>

<p>So if you ever find yourself texting someone who you can see from where you are sitting. Or you say “LOL” instead of actually laughing. Be aware that most of the people around you including those your own age, probably think you are a &lt;insert expletive here&gt;. </p>]]></content:encoded>
    </item>
    <item>
      <title>PreScan: SQL Schema Data Types</title>
      <link>https://docs.microsoft.com/archive/blogs/davidlean/prescan-sql-schema-data-types</link>
      <pubDate>Thu, 18 Nov 2010 18:36:13 GMT</pubDate>
      <dc:creator><![CDATA[davele]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/davidlean/2010/11/18/prescan-sql-schema-data-types/</guid>
      <description><![CDATA[Continuing on from my previous post PreScan: SQL Database Schema Distribution this Scan looks at the...]]></description>
      <content:encoded><![CDATA[<p>Continuing on from my previous post <a title="Quick Appraisal Phase of a Perf Tuning Excersise" href="https://blogs.msdn.com/b/davidlean/archive/2010/11/15/prescan-sql-database-schema-distribution.aspx" target="_blank">PreScan: SQL Database Schema Distribution</a> this Scan looks at the datatypes used in the database you need to tune. </p>  <p>Perhaps one of the less useful of the pre-scans it is still handy. It highlights the use of depreciated datatypes, new feature usage &amp; uncommon design. So it really doesn't matter how many INT's or VARCHAR's there are. You are looking to see if the less common datatypes are in use. </p>  <p>It is background info &amp; will only hold your attention for 1-3 mins. But may alert you to something out of the ordinary. Remember to run it against the Model database first. This it the template for all User databases &amp; holds the System Schema. So if model holds 2 sql_variant cols then sql_variant is only interesting if there is more than 2 in your database.    <br /></p>  <h3>Some of the things I look for are :-</h3>  <blockquote>   <p><strong><u>NTEXT, TEXT &amp; IMAGE fields</u></strong> Eventually these will need to converted to NVARCHAR(MAX), VARCHAR(MAX) &amp; VARBINARY(MAX) or they will block a future upgrade. Also they lets you use TSQL String functions &amp; can remove some messy special code. Might be an opportunity to speed up searches by using Full Text, could also consider FileStream to improve performance &amp; streamline operations. </p>    <p><strong><u>User Defined Types</u> </strong>I like these as they reduce the potential for error by ensuring data type consistency throughout the schema. Especially useful for key columns &amp; commonly used attributes like Surname, Phone &amp; Address fields. But you need to get them right as changing them is a nightmare.&#160; </p>    <p><strong><u>SQL_VARIANT</u></strong> This sets off an alarm bell as usually it means some attempt at Object Relational Design or a central Application Parameter table. Both can cause huge locking issues &amp; overhead, so it is often worthwhile to examine closely. Note: The system schema in SQL2008 has 2, ignore these.</p>    <p><strong><u>UNIQUEIDENTIFIER</u></strong>&#160; I’ve never been a huge fan of this 16 byte datatype. But it is handy for storing GUIDS. I have seen people use these for primary keys, yet have no code to deal with the very small but real possibility of a duplicate primary key. Many use them to resolve the issues of replicated systems, I prefer a composite key with a site ID, but can see merit in the GUID approach. Others use it to hibernate Objects in their code into the database. Whatever the reason, examine it closely as often there are more efficient alternatives.</p>    <p><strong><u>TIMESTAMP</u></strong> Often this is used to implement Optimistic Concurrency Control which is basically a way to free up record locks by rolling your own transaction. I feel this approach is inferior to Optimistic Concurrency Control by Value. Where instead of looking to see if the timestamp has changed since you read the record, you look to see if any of the values you want to change are different. This increased concurrency as it permits multiple people to simultaneously update different fields in the same row without collision. For that reason I dislike seeing timestamp cols. Note: TIMESTAMP is an 8 byte binary counter which increments each time the row is modified, it has nothing to do with the actual time.</p>    <p><strong><u>FLOAT</u></strong> is rarely useful in business systems due to its lack of precision. Check they aren’t storing financial data in float types. For most applications Financial Transactions should be stored in Money (or SmallMoney) it holds up to 4 decimal digits ie 1/100 cent). However Financial Institutions, Interest Rate calculations or Overseas currency amounts should consider Decimal. FOREX rates are quoted in fractional PIPs (5 decimal digits) so don’t use the default storage for Decimal. Reduce the bytes to consume the precision you actually need. </p>    <p><strong><u>XML</u></strong> Extensive use of XML is neither good nor bad. It is bad if you are trying to put your entire database into 1 XML field. But generally it is underused by DBA’s &amp; can be a very powerful, efficient solution when used correctly. </p>    <p><strong><u>GEOGRAPHY, GEOMETRY</u></strong> There are spatial aspects to this database.&#160; </p>    <p><strong><u>HIERARCHYID</u></strong> Could be good. Many schemas have recursive structures which often cause pain. If they have converted it to HierarchyID may be 1 less problem to solve. That said, HierarchyID’s aren’t the magical solution I’d hoped they would be. You do need to manage their updates carefully which can be a source of data corruption.&#160; </p>    <p><strong><u>BINARY &amp; BIT</u></strong> Bitmasks &amp; Flags suggest a more sophisticated algorithm most often it is a good thing. It is worth finding out what they are doing. Rarely will this be a bottleneck, but large binary fields can be a workaround for IMAGE, so FileStream might be relevant. </p>    <p><strong><u>SMALLINT, TINYINT, SMALLMONEY, SMALLDATETIME</u></strong> tell me the DBA was concerned with efficient storage &amp; actually looked at range of values contained in each field. Boosts your confidence in this design. </p>    <p><strong><u>DATE, DATETIME2</u></strong> or some of the new Date types introduced in SQL 2008. Suggest the schema was enhanced or designed recently. It is less likely to have the common bottlenecks caused by trimming Time from Dates. But also raises a flag if the data is being consumed by SSIS or SSAS. These apps will process the higher precision of DATETIME2 but most of their TIME functions do not recognise DATETIME2 as a valid input format. This can be a pain. Similarly all the ParallelPeriod style functions in SSAS &amp; PowerPivot think Date is the lowest granularity. So you need to do your own thing if you want to analyse in Hourly, 5 min, Min or Second.</p>    <p><strong><u>NVARCHAR / NCHAR vs VARCHAR / CHAR</u></strong> Neither is correct, but useful to see if they are used consistently. Joins, Filters &amp; Comparisons between ASCII &amp; Unicode types will cause implicit conversions. This may result in an an Index Scan rather than an Index Seek. It can be a pain dealing with Sorting &amp; Collation sequences. It slows development as UI interface may require different datatypes to hold the double byte characters &amp; often the programmers don’t even think about it.&#160; It also may cause problems if your company expands into overseas markets &amp; parts of your application can deal with different characters &amp; other parts break. If your entire database is Varchar / Char then you gain from reduced storage, reduced IO &amp; more data remaining in cache. But you lose language flexibility. Either way make a decision &amp; be consistent. The exception here is tables hold state internal to your application. They could be char while the rest of the system is NChar as they will never hold data inputed by the end user.</p> </blockquote>  <p>&#160;</p>  <h4>Sample of TSQL for this type of Pre-Scan</h4>&#160;&#160; <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">/* =========================================</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">Pre-Scan: DataTypes of Columns</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">Notes: What to look for :-</p>  <p style="margin: 0in 0in 0in 1.125in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">Depreicated types: Image, Text</p>  <p style="margin: 0in 0in 0in 1.125in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">New types: XML, Spatial (Geometry/Geography), CLR, HeirarchyID, DateTime+</p>  <p style="margin: 0in 0in 0in 1.125in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">Challenging types: uniqueidentifier (GUID), sql_variant, binary (what for)</p>  <p style="margin: 0in 0in 0in 1.125in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">User-Defined Types: Are they extensive? </p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- =======================================*/</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: gray">;</span><span style="color: blue">WITH</span> cols <span style="color: blue">AS </span><span style="color: gray">(</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> T<span style="color: gray">.</span>name <span style="color: blue">AS</span> [DataType]<span style="color: gray">,</span> C<span style="color: gray">.*</span> </p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">FROM</span> <span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">types</span> <span style="color: blue">AS</span> T</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: gray">JOIN</span> <span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">columns</span> <span style="color: blue">AS</span> C <span style="color: blue">ON</span> C<span style="color: gray">.</span>system_type_id <span style="color: gray">=</span> T<span style="color: gray">.</span>system_type_id</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: gray">)</span> </p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: fuchsia">COUNT</span><span style="color: gray">(*)</span> <span style="color: blue">AS</span> <span style="color: fuchsia">Count</span><span style="color: gray">,</span> DataType</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">--, name, </p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">--MIN(datatype)</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">FROM</span> cols</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">GROUP</span> <span style="color: blue">BY</span> DataType</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">-- HAVING</span> <span style="color: fuchsia">COUNT</span><span style="color: gray">(*)</span> <span style="color: gray">&gt;</span> 10</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">ORDER</span> <span style="color: blue">BY</span> 1 <span style="color: blue">DESC</span></p>  <h4>&#160;</h4>  <h4>Sample of Output</h4>  <blockquote>   <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/7043.PreScan%20Datatype%20Examples_6.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/7043.PreScan-Datatype-Examples_5F00_6.jpg"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="PreScan Datatype Examples" border="0" alt="PreScan Datatype Examples" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/8055.PreScan%20Datatype%20Examples_thumb_2.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/8055.PreScan-Datatype-Examples_5F00_thumb_5F00_2.jpg" width="644" height="280" /></a></p>    <p>In the above example I’m comparing the distribution of datatypes in a few production databases. </p>    <p>The Model database is a set of tables included in every database you create. I’ve highlighted in Purple some of the datatypes of interest. In the other databases, if they are completely purple then they aren’t using that type in any of the user tables. Where I’ve highlighted they numbers then you need to subtract from model to calculate the real number. </p> </blockquote>  <blockquote>   <p><u>Legend</u></p> </blockquote>  <blockquote>   <p>Red: Depreciated features Text &amp; Image.     <br />The Orange bands draw your attention to the Float vs Money discussion.       <br />The Dark Green is New feature usage.      <br />Light Green: they considered the range of values the column will hold &amp; didn’t blindly map everything to INT.      <br />Blues: ASCII vs Unicode chars.      <br />Yellow: Explore how these are being used. </p> </blockquote>  <h5>Quick Impressions:</h5>  <blockquote>   <p>Debtrak: Mainly ASCII based app. Need to check the use of Float &amp; financial info. What are they using Text &amp; Image for? (Probably to hold Scanned Documents)</p>    <p>&#160;<strong>Oh:</strong> No Money Types, how is float being used. Mostly NChar but not all, why are the Char types different. What are they using GUID’s for? (possibly as keys for Scanned Images). Lots of Image fields. No Money, Is this CRM or are they using Decimal instead?</p>    <p>Spinn: UID’s are huge, bet it is used for all PK &amp; FK’s, bummer. What are the Bit fields for?&#160; No Date / Time fields probably written pre-2008. More Char than INT fields, probably CRM or text based system, clearly UID’s could be considered INT’s for this comparison. </p>    <p>ReportServer: Database used by SSRS. I leave it to you to check out why they are using GUID’s, Binary &amp; Image fields. You can bet there will be some redesign when they ship the next SQL release. </p>    <p>AssetTrax: Uses Spatial Fields, Unicode &amp; not much else. Probably a central store for a Mobile GPS system, perhaps it is an optional module for a bigger system. </p>    <p><strong>SRDDBA:</strong> No Unicode, mainly Numbers, Dates, Characters. The 17 Numeric types could hold financials but I’d suspect this to be non-financial app, perhaps reference data. </p> </blockquote>  <p>I hope you find this useful, Let me know if you want me to publish more scans.</p>  <p>Dave</p>]]></content:encoded>
    </item>
    <item>
      <title>How to: See SharePoint 2010 Data Connections from Excel 2010</title>
      <link>https://docs.microsoft.com/archive/blogs/davidlean/how-to-see-sharepoint-2010-data-connections-from-excel-2010</link>
      <pubDate>Sun, 14 Nov 2010 20:29:32 GMT</pubDate>
      <dc:creator><![CDATA[davele]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/davidlean/2010/11/14/how-to-see-sharepoint-2010-data-connections-from-excel-2010/</guid>
      <description><![CDATA[&#160;  Recently I tore my hair out trying to create a great end-user experience for my Excel 2010...]]></description>
      <content:encoded><![CDATA[<p>&#160;</p>  <p>Recently I tore my hair out trying to create a great end-user experience for my Excel 2010 users when they access SharePoint. </p>  <p>Eventually I found a way to get it to work. This is not a perfect post. I’m far from an expert in SharePoint &amp; I’m hoping a sharepoint expert will comment &amp; show me a slicker way. But given I found nothing on the net, I hope this may assist you.</p>  <h2>The Goal. </h2>  <p>A Sharepoint person should publish a set of connections to data sources &amp; provide permissions to all who need them. All end users automatically see them. Some time later as IT moves the databases &amp; data to new servers, they update the sharepoint data connection libraries &amp; the hundreds of business users don’t notice &amp; don’t care.</p>  <h2>What I wanted the Business user to experience</h2>  <p>Step 1: Open Excel &amp; click on Existing Connections    <br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/3173.image_2.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/3173.image_5F00_2.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/8688.image_thumb.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/8688.image_5F00_thumb.png" width="244" height="99" /></a></p>  <p>Step 2: See something in the “Connection files on the Network”. Double click on one of the Sharepoint Data Connection Libraries listed.    <br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/0830.image_4.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/0830.image_5F00_4.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/0434.image_thumb_1.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/0434.image_5F00_thumb_5F00_1.png" width="207" height="244" /></a></p>  <p>Step 3: Select the Data Source they want.    <br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/7128.image_6.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/7128.image_5F00_6.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/2806.image_thumb_2.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/2806.image_5F00_thumb_5F00_2.png" width="209" height="244" /></a></p>  <p>Step 4: Use it in Excel.    <br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/0743.image_8.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/0743.image_5F00_8.png"><img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/0456.image_thumb_3.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/0456.image_5F00_thumb_5F00_3.png" width="244" height="202" /></a></p>  <p>&#160;</p>  <h2>How to do it – Sharepoint Site Admin. </h2>  <p>Step 1: Open <strong>Sharepoint 2010 Central Administration</strong> app &amp; click <font color="#ff0000"><strong>Manage Service Applications        <br /></strong></font><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/0755.image_10.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/0755.image_5F00_10.png"><img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/7230.image_thumb_4.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/7230.image_5F00_thumb_5F00_4.png" width="244" height="148" /></a></p>  <p>Step 2: Check the Excel Services Application has been installed &amp; started.    <br />(As this process is reasonably well documented elsewhere I’ll not repeat it here)     <br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/8780.image_14.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/8780.image_5F00_14.png"><img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/8206.image_thumb_6.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/8206.image_5F00_thumb_5F00_6.png" width="222" height="244" /></a></p>  <p>Step 3: Click <strong><font color="#ff0000">User Profile Service Application        <br /></font></strong><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/1447.image_12.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/1447.image_5F00_12.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/1854.image_thumb_5.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/1854.image_5F00_thumb_5F00_5.png" width="222" height="244" /></a></p>  <p>Step 4: Click “<font color="#ff0000"><strong>Publish links to Office Client Applications</strong></font>”     <br />This bit took me ages to find, as it was in a different location in Sharepoint 2007 &amp; all the 2010 doc’s I found still had Sharepoint 2007 pictures in it.     <br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/5164.image_16.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/5164.image_5F00_16.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/2844.image_thumb_7.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/2844.image_5F00_thumb_5F00_7.png" width="644" height="334" /></a></p>  <p>Step 5: Click <strong><font color="#ff0000">New Link</font></strong>     <br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/5164.image_18.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/5164.image_5F00_18.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/5008.image_thumb_8.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/5008.image_5F00_thumb_5F00_8.png" width="644" height="330" /></a></p>  <p>Step 6: Paste in the URL to the Sharepoint Data Connection Library that you’ve created earlier.    <br />NB: If you don’t have one, now would be a very good time to     <br />a) Create a Data Connection Library (DCL),     <br />b) Create a Data Connection     <br />c) Upload it into Sharepoint &amp;     <br />d) Give permissions &amp; Approve both the Library &amp; the Data Connection.     <br />(As these steps are also well doc’ed I’ll not repeat them here. )     <br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/0383.image_20.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/0383.image_5F00_20.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/0602.image_thumb_9.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/0602.image_5F00_thumb_5F00_9.png" width="644" height="319" /></a></p>  <h2>&#160;</h2>  <h2>How to do it – Excel Client Admin. </h2>  <p>Note: This is the part I think it insane. It works, it is in the official documentation for older versions of Sharepoint. But I suspect there is much better way to do this. Some have told me “Yes we do that, but we push it out via group policy”. I can’t imaging anyone in the Sharepoint team architecting this &amp; deciding it was the recommended way to do this. So there is probably a script or button somewhere but I’ve not found it.</p>  <p>Step 1. Open up RegEdit.Exe.    <br />(Note: You are about to edit the Windows Registry. Good idea to back it up first. If you stuff it up you may create serious issues that may prevent your computer from starting &amp; cause you to reinstall windows.)</p>  <p>Step 2:&#160; Move to Key <font color="#ff0000"><strong>HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Common\Server Links\Published</strong></font>     <br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/3835.image_22.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/3835.image_5F00_22.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/6560.image_thumb_10.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/6560.image_5F00_thumb_5F00_10.png" width="644" height="360" /></a></p>  <p>Step 3: Right Click on Published &amp; add a new String Key.    <br />Call it anything you like, this will be the name that appears in the Excel “Existing Connections” Dialog. As you can see above I called mine “Secure Data Connections” as that was the name of the Sharepoint DCL I created &amp; management liked the idea of it being secure. </p>  <p>Step 4: Set the value to the key to URL to point to the Sharepoint Data Connection Library you created. <a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/5008.image_24.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/5008.image_5F00_24.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/2330.image_thumb_11.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/2330.image_5F00_thumb_5F00_11.png" width="644" height="272" /></a></p>  <p>Step 5: Enjoy. </p>  <p>Note: The environment I set this up was had a crazy design for the Windows Authentication in their Test domain. So I’m unsure if some of the Trust &amp; Security warnings I was receiving from Excel was something others would see. If you also get “Click here to trust this data” try looking in the Excel Trust Centre &amp; Trusted Locations / Documents areas.&#160; </p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/0880.image_26.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/0880.image_5F00_26.png"><img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/6562.image_thumb_12.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/6562.image_5F00_thumb_5F00_12.png" width="244" height="177" /></a>&#160;<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/6175.image_28.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/6175.image_5F00_28.png"><img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/8625.image_thumb_13.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/8625.image_5F00_thumb_5F00_13.png" width="244" height="150" /></a></p>  <p>&#160;</p>  <p><font size="4">Like I said at the start. I usually prefer to present well researched material &amp; have a “this is the way to do it” blog. But in this case the goal is to help you break thru a few of the issues I had &amp; maybe move you closer to a solution.</font></p>  <p><font size="4">Feel free to add comments if you have more insight on this process. </font></p>  <p><font size="4">Thanks Dave. </font></p>]]></content:encoded>
    </item>
    <item>
      <title>PreScan: SQL Database Schema Distribution</title>
      <link>https://docs.microsoft.com/archive/blogs/davidlean/prescan-sql-database-schema-distribution</link>
      <pubDate>Sun, 14 Nov 2010 19:17:51 GMT</pubDate>
      <dc:creator><![CDATA[davele]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/davidlean/2010/11/14/prescan-sql-database-schema-distribution/</guid>
      <description><![CDATA[&#160;    At the very start of a performance tuning exercise I do a Quick Appraisal to assess what...]]></description>
      <content:encoded><![CDATA[&#160; <ol>   <p style="margin: 0in; font-family: calibri; font-size: 11pt">At the very start of a performance tuning exercise I do a Quick Appraisal to assess what I'm dealing with.<span style="mso-spacerun: yes">&#160; </span>This is one of a number of “information collection” scripts I run. </p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt">This post shows (a) Code &amp; (b) some ideas on insight you can get from it. </p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>    <h1><span style="font-family: calibri; font-size: 17pt">What are PreScans?</span></h1>    <p style="margin: 0in; font-family: calibri; font-size: 11pt">When someone has a performance problem they often expect you to &quot;know” everything about their system &amp; pinpoint the problems almost before you’ve even seen their system. To bring me up to speed fast, I run a series of trivial light weight queries that give me some statistics &amp; a rough idea of what I’m dealing with. I run these Database scans prior to starting a job, hence the term “Pre-Scan” or “Quick Appraisal” phase.</p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160; </p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt">As I mentioned my “Quick Appraisal” set of queries in a recent presentation to the Sydney SQL Server User Group. I thought I’d post a few on my blog.&#160; This is one of them. Note, this is not an in-depth anything, often a 5 sec glance at the results is sufficient. But after looking thru 10-15 of these simple queries, it is amazing how accurate your “first impressions” will be for speculating on the potential problem areas of a system. </p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>    <p style="margin: 0in; font-family: calibri; font-size: 17pt"><span style="font-family: calibri; font-size: 17pt"></span></p>    <h1><span style="font-family: calibri; font-size: 17pt">Quick Appraisal</span></h1>    <p style="margin: 0in; font-family: calibri; font-size: 11pt">There are many different styles of database design.<span style="mso-spacerun: yes">&#160; </span>Looking at the number of Objects, the types of Objects &amp; ratios between them, often permits you to make a quick assessment on both the complexity of the database as well as the mindset of those who created it. Knowing this &quot;mindset&quot; permits you assess the probability of where their poor coding practices might lie.<span style="mso-spacerun: yes">&#160;</span></p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt">Is it unfair to assume there are suboptimal coding practices in the database? No, no-one<span style="mso-spacerun: yes">&#160; will every pay you </span>to tune a system that they think is working well. There is bound to be a bottleneck somewhere. Most organisations will have already tried “throw more H/W at it”&#160; ;-)</p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>    <h2>How does it work?</h2>    <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/2806.PreScan%20DB%20Schema%20Comparision.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/2806.PreScan-DB-Schema-Comparision.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="PreScan DB Schema Comparision" border="0" alt="PreScan DB Schema Comparision" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/1016.PreScan%20DB%20Schema%20Comparision_thumb.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/1016.PreScan-DB-Schema-Comparision_5F00_thumb.png" width="644" height="445" /></a></p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt">The above table shows output from 7 different databases. Debtrak, O4, Spinn are production systems used by very large companies. SSRS, MSDB, Master are SQL System Databases. AW08 is the SQL Sample Adventureworks database. </p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt">You will note, I’ve created a few extra rows to look at the Primary keys, Foreign Keys &amp; Stored Procs as a percentage of overall tables. </p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt"><u><strong>Debtrak:</strong></u> High Use of Stored Procedures (Could be a good thing, unless they are full of cursors). Fairly high number of tables. 1/3 of the tables have no primary key. Almost no foreign keys. But heaps of Stored Procedures, perhaps they do data integrity checks there. If not, could be heaps of duplicate rows &amp; dirty data. Using functions so schema has been developed for SQL2005+ or modified to use newer features introduced in SQL 2005. No CLR, Extended SP’s, or Service Broker, generally DBA’s who implement these in their design are highly skilled in both DBA &amp; Dev. So less likely to find any easy wins.</p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt"><strong></strong></p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt"><u><strong>O4:</strong></u> Lots of Tables &amp; views. Need to check on the PK use, only 8% don’t have them. Very few FK’s so Declarative Referential Integrity (DRI) is not used much, probably done with rules. Lots of Rules, database likely to created on pre-SQL2000 &amp; upgraded. Watch for depreciated items, especially Text &amp; image fields &amp; functions that trim the time off dates. Quite a few triggers, need to check how complex they are. </p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt"><strong><u>Spinn</u>:</strong> Lots of FK’s (so extremely heavy use of DRI = good), No views or Stored procs. Probably created by a programmer, where all data integrity would be handled by their application. Their app will generate TSQL. This would be a nightmare to tune unless they have Unit &amp; Load tests created for their code. At best you will be creating indexes or playing with H/W. I’d expect to find a lot of dirty data as very few applications do a good job at checking anything other than the datatypes &amp; a drop down list of values. The relations between the fields in a row are often not checked at all eg: This results in Pregnant males, Customers born in the future, Orders delivered before they were placed &amp; 32 year old Primary School students. At least the relationships between rows should be good.</p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt"><u><strong>SSRS (SQL Reporting Services):</strong></u> Good use of Stored Procs &amp; FK’s. Very few tables. Not a lot to look at, easy to understand. </p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt"><u><strong>AdventureWorks 2008:</strong></u> Modest number of tables. DRI is brilliant, data likely to be of good quality, especially when you look at the number of Rules &amp; Check constraints. Few stored procs, so app likely to be passing TSQL. Rules also suggest an older design, so look for depreciated constructs. </p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt"><u><strong>Master:</strong></u> The numbers suggest there are many things wrong with this database. The only good news is that a tiny number of tables suggest it is not used by more than 1 app. Of course in this case we know that since SQL2005 the Master DB was split in two. The other part is the resource database, which is not shown here. So it makes little sense drawing any conclusion about it other than “Hey it is a small number of tables, should be easy to figure out what they do.”</p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>    <h2>Sample of TSQL for this type of Pre-Scan</h2>    <p style="margin: 0in; font-family: calibri; font-size: 11pt; font-weight: bold; text-decoration: underline">Version 1.<span style="mso-spacerun: yes">&#160; </span>- Faster, Sort in Order you want. </p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt">Only shows objects that exist. It will also display new Objects Types if they are introduced in future versions of SQL</p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>    <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">USE</span> O4Jul09</p>    <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">go</p>    <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: gray">;</span><span style="color: blue">WITH</span> ObjectTypes <span style="color: blue">AS </span><span style="color: gray">(</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> [type]<span style="color: gray">,</span> type_desc<span style="color: gray">,</span> <span style="color: fuchsia">COUNT</span><span style="color: gray">(*)</span> <span style="color: blue">AS</span> [Count]</p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">FROM</span> <span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">objects</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">GROUP</span> <span style="color: blue">BY</span> [type]<span style="color: gray">,</span> type_desc</p>    <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: gray">)</span> </p>    <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: gray">*</span></p>    <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">FROM</span> ObjectTypes</p>    <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">ORDER</span> <span style="color: blue">BY</span> <span style="color: blue">CASE</span> [type]</p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHEN</span> <span style="color: red">'SN'</span> <span style="color: blue">THEN</span> 10 <span style="color: green">-- Synonym</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHEN</span> <span style="color: red">'V'</span> <span style="color: blue">THEN</span> 11 <span style="color: green">-- View</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHEN</span> <span style="color: red">'U'</span> <span style="color: blue">THEN</span> 20 <span style="color: green">-- User Table</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHEN</span> <span style="color: red">'PK'</span> <span style="color: blue">THEN</span> 21 <span style="color: green">-- PRIMARY KEY constraint</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHEN</span> <span style="color: red">'F'</span> <span style="color: blue">THEN</span> 22 <span style="color: green">-- FOREIGN KEY constraint</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHEN</span> <span style="color: red">'UQ'</span> <span style="color: blue">THEN</span> 23 <span style="color: green">-- UNIQUE constraint</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHEN</span> <span style="color: red">'C'</span> <span style="color: blue">THEN</span> 24 <span style="color: green">-- CHECK constraint</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHEN</span> <span style="color: red">'D'</span> <span style="color: blue">THEN</span> 25 <span style="color: green">-- DEFAULT (constraint or stand-alone)</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHEN</span> <span style="color: red">'R'</span> <span style="color: blue">THEN</span> 26 <span style="color: green">-- Rule (old-style, stand-alone)</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHEN</span> <span style="color: red">'TR'</span> <span style="color: blue">THEN</span> 30 <span style="color: green">-- SQL Trigger</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHEN</span> <span style="color: red">'SQ'</span> <span style="color: blue">THEN</span> 31 <span style="color: green">-- Service queue</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHEN</span> <span style="color: red">'P'</span> <span style="color: blue">THEN</span> 40 <span style="color: green">-- SQL Stored Procedure</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHEN</span> <span style="color: red">'TF'</span> <span style="color: blue">THEN</span> 41 <span style="color: green">-- SQL Table-valued-function</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHEN</span> <span style="color: red">'IF'</span> <span style="color: blue">THEN</span> 42 <span style="color: green">-- SQL Inline Table-valued function</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHEN</span> <span style="color: red">'FN'</span> <span style="color: blue">THEN</span> 43 <span style="color: green">-- SQL Scalar function</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHEN</span> <span style="color: red">'X'</span> <span style="color: blue">THEN</span> 50 <span style="color: green">-- Extended stored procedure</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHEN</span> <span style="color: red">'RF'</span> <span style="color: blue">THEN</span> 51 <span style="color: green">-- Replication-filter-procedure</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHEN</span> <span style="color: red">'PC'</span> <span style="color: blue">THEN</span> 60 <span style="color: green">-- Assembly (CLR) stored-procedure</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHEN</span> <span style="color: red">'FT'</span> <span style="color: blue">THEN</span> 61 <span style="color: green">-- Assembly (CLR) table-valued function</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHEN</span> <span style="color: red">'FS'</span> <span style="color: blue">THEN</span> 62 <span style="color: green">-- Assembly (CLR) scalar-function</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHEN</span> <span style="color: red">'AF'</span> <span style="color: blue">THEN</span> 63 <span style="color: green">-- Aggregate function (CLR)</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHEN</span> <span style="color: red">'TA'</span> <span style="color: blue">THEN</span> 64 <span style="color: green">-- Assembly (CLR) DML trigger</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHEN</span> <span style="color: red">'PG'</span> <span style="color: blue">THEN</span> 80 <span style="color: green">-- Plan guide</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHEN</span> <span style="color: red">'IT'</span> <span style="color: blue">THEN</span> 90 <span style="color: green">-- Internal table</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHEN</span> <span style="color: red">'S'</span> <span style="color: blue">THEN</span> 91 <span style="color: green">-- System table</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHEN</span> <span style="color: red">'TT'</span> <span style="color: blue">THEN</span> 92 <span style="color: green">-- TYPE_TABLE </span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">ELSE</span> 100 </p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">END</span> </p>    <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">go</p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt; font-weight: bold; text-decoration: underline">Version 2.<span style="mso-spacerun: yes">&#160; </span>- Slightly Slower.<span style="mso-spacerun: yes">&#160; </span>Highlights which object types the schema doesn't use.<span style="mso-spacerun: yes">&#160; </span></p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt">Only shows objects that exist</p>    <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt">&#160;</p>    <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">USE</span> O4Jul09</p>    <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">go</p>    <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: gray">;</span><span style="color: blue">WITH</span> ObjectTypes <span style="color: blue">AS </span><span style="color: gray">(</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> [type]<span style="color: gray">,</span> type_desc<span style="color: gray">,</span> <span style="color: fuchsia">COUNT</span><span style="color: gray">(*)</span> <span style="color: blue">AS</span> [Count]</p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">FROM</span> <span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">objects</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">GROUP</span> <span style="color: blue">BY</span> [type]<span style="color: gray">,</span> type_desc</p>    <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">)</p>    <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: gray">,</span> ObjectGroups <span style="color: blue">AS </span><span style="color: gray">(</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: red">'SN'</span> <span style="color: blue">AS</span> [type] <span style="color: gray">,</span> 10 <span style="color: blue">AS</span> SortOrder<span style="color: gray">,</span> <span style="color: red">'Synonym'</span> <span style="color: blue">AS</span> type_desc<span style="color: gray">,</span> <span style="color: red">'Any Redirection to be aware of?'</span> <span style="color: blue">AS</span> <span style="color: blue">Action</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: red">'V'</span> <span style="color: gray">,</span> 11 <span style="color: gray">,</span> <span style="color: red">'View'</span><span style="color: gray">,</span> <span style="color: red">'Does it make extensive use of Views?'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: gray">NULL,</span> 19<span style="color: gray">,</span> <span style="color: red">'.'</span><span style="color: gray">,</span> <span style="color: red">'.'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">--&lt; User Tables &gt;--</p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: red">'U'</span> <span style="color: gray">,</span> 20<span style="color: gray">,</span> <span style="color: red">'User TABLE'</span><span style="color: gray">,</span> <span style="color: red">'Amount of tables'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: red">'PK'</span><span style="color: gray">,</span> 21<span style="color: gray">,</span> <span style="color: red">'PRIMARY KEY constraint'</span><span style="color: gray">,</span> <span style="color: red">'% of Tables with PK''s defined'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: red">'F'</span> <span style="color: gray">,</span> 22<span style="color: gray">,</span> <span style="color: red">'FOREIGN KEY constraint'</span><span style="color: gray">,</span> <span style="color: red">'Are they using DRI?'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: red">'UQ'</span><span style="color: gray">,</span> 23<span style="color: gray">,</span> <span style="color: red">'UNIQUE constraint'</span><span style="color: gray">,</span> <span style="color: red">'Check M:M join tables are correctly protected'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: red">'C'</span> <span style="color: gray">,</span> 24<span style="color: gray">,</span> <span style="color: red">'CHECK constraint'</span><span style="color: gray">,</span> <span style="color: red">'Are Data values protected by schema?'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: red">'D'</span> <span style="color: gray">,</span> 25<span style="color: gray">,</span> <span style="color: red">'DEFAULT (constraint or stand-alone)'</span><span style="color: gray">,</span> <span style="color: red">'Do they rely on Defaults or SPs or nothing'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: red">'R'</span> <span style="color: gray">,</span> 25<span style="color: gray">,</span> <span style="color: red">'RULE (old-style, stand-alone)'</span><span style="color: gray">,</span> <span style="color: red">'Are they using Depreciated Checks'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: gray">NULL,</span> 29<span style="color: gray">,</span> <span style="color: red">'.'</span><span style="color: gray">,</span> <span style="color: red">'.'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">--</p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: red">'TR'</span><span style="color: gray">,</span> 30<span style="color: gray">,</span> <span style="color: red">'TRIGGER'</span><span style="color: gray">,</span> <span style="color: red">'Look at ratio vs User Tables. Heavy / Light use of Triggers?'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">--&lt; SQL Broker &gt;--</p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: red">'SQ'</span><span style="color: gray">,</span> 31<span style="color: gray">,</span> <span style="color: red">'Service QUEUE'</span><span style="color: gray">,</span> <span style="color: red">'Are they using Async &quot;Triggers&quot; or SQL Broker?'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: gray">NULL,</span> 39<span style="color: gray">,</span> <span style="color: red">'.'</span><span style="color: gray">,</span> <span style="color: red">'.'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">--&lt; Procedural Code &gt;--</p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: red">'P'</span> <span style="color: gray">,</span> 40<span style="color: gray">,</span> <span style="color: red">'Stored Procedure'</span><span style="color: gray">,</span> <span style="color: red">'Number &amp; Ratio to User Tables'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: red">'TF'</span><span style="color: gray">,</span> 41<span style="color: gray">,</span> <span style="color: red">'Table-Valued-function'</span><span style="color: gray">,</span> <span style="color: red">'Are they being used?'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: red">'IF'</span><span style="color: gray">,</span> 42<span style="color: gray">,</span> <span style="color: red">'Inline Table-Valued function'</span><span style="color: gray">,</span> <span style="color: red">'Are they being used?'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: red">'FN'</span><span style="color: gray">,</span> 43<span style="color: gray">,</span> <span style="color: red">'Scalar function'</span><span style="color: gray">,</span> <span style="color: red">'Are they being used?'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: gray">NULL,</span> 49<span style="color: gray">,</span> <span style="color: red">'.'</span><span style="color: gray">,</span> <span style="color: red">'.'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">--</p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: red">'X'</span><span style="color: gray">,</span> 50<span style="color: gray">,</span> <span style="color: red">'Extended stored procedure'</span><span style="color: gray">,</span> <span style="color: red">'Need to think about security'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: red">'RF'</span><span style="color: gray">,</span> 51<span style="color: gray">,</span> <span style="color: red">'Replication-filter-procedure'</span><span style="color: gray">,</span> <span style="color: red">'Will need to think about external connections'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: gray">NULL,</span> 59<span style="color: gray">,</span> <span style="color: red">'.'</span><span style="color: gray">,</span> <span style="color: red">'.'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">--&lt; CLR Use &gt;--</p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: red">'PC'</span> <span style="color: gray">,</span> 60<span style="color: gray">,</span> <span style="color: red">'Assembly (CLR) stored-procedure'</span><span style="color: gray">,</span> <span style="color: red">'Are they useing CLR?'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: red">'FT'</span><span style="color: gray">,</span> 61<span style="color: gray">,</span> <span style="color: red">'Assembly (CLR) table-valued function'</span><span style="color: gray">,</span> <span style="color: red">'Are they useing CLR?'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: red">'FS'</span><span style="color: gray">,</span> 62<span style="color: gray">,</span> <span style="color: red">'Assembly (CLR) scalar-function'</span><span style="color: gray">,</span> <span style="color: red">'Are they useing CLR?'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: red">'AF'</span><span style="color: gray">,</span> 63<span style="color: gray">,</span> <span style="color: red">'Aggregate function (CLR)'</span><span style="color: gray">,</span> <span style="color: red">'Are they useing CLR?'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: red">'TA'</span><span style="color: gray">,</span> 64<span style="color: gray">,</span> <span style="color: red">'Assembly (CLR) DML trigger'</span><span style="color: gray">,</span> <span style="color: red">'Are they useing CLR?'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: gray">NULL,</span> 69<span style="color: gray">,</span> <span style="color: red">'.'</span><span style="color: gray">,</span> <span style="color: red">'.'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: gray">NULL,</span> 79<span style="color: gray">,</span> <span style="color: red">'.'</span><span style="color: gray">,</span> <span style="color: red">'.'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt"><span style="mso-spacerun: yes">&#160;&#160;&#160; </span>--&lt; Other &gt;--</p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: red">'PG'</span><span style="color: gray">,</span> 80<span style="color: gray">,</span> <span style="color: red">'Plan guide'</span><span style="color: gray">,</span> <span style="color: red">'Some serious compatibility work has been done on this DB'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: gray">NULL,</span> 89<span style="color: gray">,</span> <span style="color: red">'.'</span><span style="color: gray">,</span> <span style="color: red">'.'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">--</p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: red">'IT'</span><span style="color: gray">,</span> 90<span style="color: gray">,</span> <span style="color: red">'INTERNAL_TABLE'</span><span style="color: gray">,</span> <span style="color: red">'-'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: red">'S'</span> <span style="color: gray">,</span> 91<span style="color: gray">,</span> <span style="color: red">'SYSTEM_TABLE'</span><span style="color: gray">,</span> <span style="color: red">'-'</span> <span style="color: blue">UNION</span> <span style="color: gray">ALL</span></p>    <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: red">'TT'</span><span style="color: gray">,</span> 92<span style="color: gray">,</span> <span style="color: red">'TYPE_TABLE'</span><span style="color: gray">,</span> <span style="color: red">'-'</span></p>    <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">)</p>    <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: fuchsia">COALESCE</span><span style="color: gray">(</span>G<span style="color: gray">.</span>[type]<span style="color: gray">,</span> T<span style="color: gray">.</span>[type]<span style="color: gray">,</span> <span style="color: red">'.'</span><span style="color: gray">)</span> <span style="color: blue">AS</span> <span style="color: blue">Type</span><span style="color: gray">,</span> <span style="color: fuchsia">COALESCE</span><span style="color: gray">(</span>G<span style="color: gray">.</span>type_desc<span style="color: gray">,</span> T<span style="color: gray">.</span>type_desc<span style="color: gray">)</span> <span style="color: blue">AS</span> [Type Description]<span style="color: gray">,</span> <span style="color: fuchsia">ISNULL</span><span style="color: gray">(</span><span style="color: fuchsia">CAST</span><span style="color: gray">(</span>T<span style="color: gray">.</span>[Count] <span style="color: blue">AS</span> <span style="color: blue">VARCHAR</span><span style="color: gray">(</span>8<span style="color: gray">)),</span> <span style="color: red">'.'</span><span style="color: gray">)</span> <span style="color: blue">AS</span> Quantity<span style="color: gray">,</span> G<span style="color: gray">.</span><span style="color: blue">Action</span></p>    <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">FROM</span> ObjectGroups <span style="color: blue">AS</span> G</p>    <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">FULL</span> <span style="color: gray">JOIN</span> ObjectTypes <span style="color: blue">AS</span> T <span style="color: blue">ON</span> T<span style="color: gray">.</span>[type] <span style="color: gray">=</span> G<span style="color: gray">.</span>[type]</p>    <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">ORDER</span> <span style="color: blue">BY</span> SortOrder</p>    <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt">&#160;</p>    <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt">&#160;</p>    <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p> </ol>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt">&#160;</p>  <h2>Examples of insight you can gain from this information.</h2>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt"></span></p>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><u><span style="font-family: calibri; font-size: 11pt">User Tables</span></u></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt; vertical-align: middle"><span style="mso-spacerun: yes">&#160;</span>The more they have the more complex the schema. Obvious huh?</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt; vertical-align: middle">&#160;</p>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><u><span style="font-family: calibri; font-size: 11pt">Primary Keys</span></u></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt; vertical-align: middle"><span style="mso-spacerun: yes">&#160;</span>Generally every table should have one. If they don't there should be a really good reason. Find out what it is. More often I hear &quot;Oh! Really&quot;, &quot;Yer well I was in a hurry that day &amp; was going to get back to it.&quot; or &quot;That was when I was new&quot; or “What’s a Primary key?”.     <br />Sometimes are good reasons eg: these are “Staging Tables” where data is bulk loaded into them, manipulated with Table scans &amp; moved on. This supports an Extract, Load &amp; Transform (ELT) style of data movement. (NB: Most people still refer to this as Extract, Transform &amp; Load (ETL) processing). You may think that this activity may be better handled in TempDB, but sometimes a complex series of batch load processes need; i)a way to pass data from one to the other or ii) die &amp; be restarted without doing everything from scratch.</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt; vertical-align: middle">&#160;</p>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><u><span style="font-family: calibri; font-size: 11pt">Foreign Keys</span> </u></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt; vertical-align: middle">Are they using Declarative Referential Integrity (DRI)? If not, Why not? </p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt; vertical-align: middle">Perhaps this is a Data warehouse &amp; the relationships were validated in the staging database or the ETL process.</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt; vertical-align: middle">Perhaps they are relying on Stored Procs &amp; Triggers - fragile &amp; possibly slow. </p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt; vertical-align: middle">You should ensure that FK Constraints have a useful index to enforce them. Without it, queries can deadlock on themselves &amp;/or cause table scans even on single row modifications.<span style="mso-spacerun: yes">&#160; </span>Note: That does not mean you should automatically create a Non-Clustered index on just that specific column. Perhaps adding another column as a composite key or as an Included field will<span style="mso-spacerun: yes">&#160; </span>permit the index to cover the needs of a commonly run query as well. </p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt; vertical-align: middle">&#160;</p>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><u><span style="font-family: calibri; font-size: 11pt">Unique Constraints</span> </u></p>  <ul>   <li>     <div style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">These may be unnecessary if the Primary Key fields were selected correctly but if there are none, it raises an alarm bell. </span></div>      <ul>       <li>         <div style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">Look for tables designed to support Many<span style="mso-spacerun: yes">&#160; </span>to Many Joins. There is a high probability they've not been indexed / constrained correctly. Resulting in duplicate rows &amp; highly inefficient queries. </span></div>       </li>        <li>         <div style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">Most databases I've seen suffer from duplicate rows. Especially ones with Web front ends that don't prevent the users from hitting OK multiple times when the interface fails to respond quickly. The only difference in the rows is the Auto-generated Primary key.<span style="mso-spacerun: yes">&#160; </span>A Unique constraint can prevent that but effectively you are creating the entire table again in the index. So use with care. It is probably better to make the two foreign Key columns a composite Primary key &amp; remove the Identity column you are currently using as a primary key. </span></div>       </li>     </ul>   </li> </ul>  <p style="margin: 0in 0in 0in 0.75in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><u><span style="font-family: calibri; font-size: 11pt">Check Constraints</span> </u></p>  <ul>   <li>     <div style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">The use of Check Constraints tends to suggest the database was designed by a DBA rather than a programmer. Programmers tend to validate the input in Stored Procedures &amp;/or their application.<span style="mso-spacerun: yes">&#160; </span>(NB: I did not say one approach was always better than the other. )</span> </div>   </li>    <li>     <div style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">Check Constraints are vital to get all the performance benefits from a Partitioned table. </span></div>   </li> </ul>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><u><span style="font-family: calibri; font-size: 11pt"></span></u></p>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><u><span style="font-family: calibri; font-size: 11pt">Default Constraints</span> </u></p>  <ul>   <li>     <div style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">Very few or zero Defaults, suggests they are setting these values in Stored Proc's or in the App code. </span></div>   </li>    <li>     <div style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">Be alert, DB's with high numbers of Default, often use the poor practise of Insert a row &amp; then immediately Select it to determine values of the Defaults &amp; Identity fields. </span></div>   </li> </ul>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt">This often results in an index search to Update/Insert a row &amp; another to select it. Also resulting in 2 network round trips, so more network traffic. </p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt">If you need to return the values generated by your Insert ie: set by Identity, Default,<span style="mso-spacerun: yes">&#160; </span>&amp; triggers.<span style="mso-spacerun: yes">&#160; </span>Use an OUTPUT Clause on your insert, instead of re-Selecting the rows you've just inserted.<span style="mso-spacerun: yes">&#160; </span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- &lt; Inefficient 2 Separate queries, 2 Network round trips &gt;--</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">INSERT</span> <span style="color: blue">INTO</span> InsertOutput<span style="color: gray">(</span>name<span style="color: gray">)</span> <span style="color: blue">VALUES</span><span style="color: gray">(</span><span style="color: red">'Dave11'</span><span style="color: gray">)</span><span style="mso-spacerun: yes">&#160;&#160;&#160; </span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">go</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: gray">*</span> <span style="color: blue">FROM</span> InsertOutput <span style="color: blue">WHERE</span> name <span style="color: gray">=</span> <span style="color: red">'Dave11'</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">go</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- &lt; More efficient 1 query, 1 Network trip, ~33+% faster &gt;--</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">INSERT</span> <span style="color: blue">INTO</span> InsertOutput<span style="color: gray">(</span>name<span style="color: gray">)</span> </p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">OUTPUT</span> inserted<span style="color: gray">.</span>ID<span style="color: gray">,</span> inserted<span style="color: gray">.</span>Name<span style="color: gray">,</span> inserted<span style="color: gray">.</span>DateIn<span style="color: gray">,</span> inserted<span style="color: gray">.</span>UserName</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">VALUES </span><span style="color: gray">(</span><span style="color: red">'Dave21'</span><span style="color: gray">)</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">go</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">&#160;</p>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><u><span style="font-family: calibri; font-size: 11pt">Rules</span></u></p>  <ul>   <li>     <div style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">If you find any, make time to rewrite them as CHECK Constraints. </span></div>   </li>    <li>     <div style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">I really liked the old style Rules, Defaults &amp; User Defined Types as they could be created once &amp; use in many tables. Thus ensuring consistency throughout the design. Unfortunately they are not ANSI compliant &amp; are depreciated. Also you needed to be sure of your decisions when you created them as changing them caused a maintenance nightmare.<span style="mso-spacerun: yes">&#160;</span></span></div>   </li> </ul>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt"><span style="mso-spacerun: yes">&#160;</span></span></p>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt"><span style="mso-spacerun: yes"></span></span></p>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><u><span style="font-family: calibri; font-size: 11pt">Triggers</span> </u></p>  <ul>   <li>     <div style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">Debugging Triggers &amp;/or assessing their impact on performance can be very tricky. Knowing that Triggers exist in the design helps you factor that into your plans. Be aware that neither sp_depends nor<span style="mso-spacerun: yes">&#160; </span>the dependency DMV's do a perfect job at looking at objects called by triggers. </span></div>   </li>    <li>     <div style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">Look for <span style="mso-spacerun: yes">&#160;</span>INSTEAD OF triggers they may completely change the impact of what you thought DML statements would do to that table. </span></div>   </li>    <li>     <div style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">Where Triggers are used to maintain other entities see if you can rewrite it using Queues. Eg: If placing a Customer order causes a trigger to fire that initiates a workflow to restock your warehouse if the stock level is low. This activity is often better handled asynchronously using SQL broker. One benefit is that your end user will get a more predictable response time when their Order placement transaction is not suddenly burdened with the overhead of restocking the warehouse.</span></div>   </li> </ul>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><u><span style="font-family: calibri; font-size: 11pt"></span></u></p>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><u><span style="font-family: calibri; font-size: 11pt">Service Queues</span> </u></p>  <ul>   <li>     <div style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">If they are not being used, it is likely that they could be beneficial .</span> </div>   </li> </ul>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle">&#160;</p>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><u><span style="font-family: calibri; font-size: 11pt">Stored Procedures</span> </u></p>  <ul>   <li>     <div style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">Look at the number compared to User Tables. </span></div>   </li>    <li>     <div style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">If there are 3 SP's for each table it is likely a poor design. An Insert, an Update &amp; a Delete<span style="mso-spacerun: yes">&#160; </span>stored procedure, is unlikely to encapsulate logic very well. </span></div>   </li>    <li>     <div style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">If there are very few SP's it is likely to become a maintenance nightmare. Without the SP's to abstract the Database schema from the application, all the queries will be created &amp; generated in code. Making changes to the schema will be almost impossible to test. (Unless they have 100% code coverage in their Unit Tests &amp; are not using Mocking to prevent the tests actually calling the DB. This is very rare)</span> </div>   </li> </ul>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle">&#160;</p>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><u><span style="font-family: calibri; font-size: 11pt">SQL Functions</span> </u></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt; vertical-align: middle">When used carefully these can improve code reuse &amp; improve performance. Most often these create big perf issues. Watch for :-</p>  <ul>   <ul>     <li>       <div style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">Calling a trivial function from within a WHERE clause, if may prevent you using an index &amp; result in a table scan.</span> </div>     </li>      <li>       <div style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">Calling a Function from a Select list. It gets called once for each row in the resultset, which could be a huge perf hit. Often it is better to rewrite the Function as part of the Join clause. </span></div>     </li>   </ul> </ul>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><u><span style="font-family: calibri; font-size: 11pt"></span></u></p>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><u><span style="font-family: calibri; font-size: 11pt">Extended Stored Procedures</span> </u></p>  <ul>   <li>     <div style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">Check security is done correctly.</span> </div>   </li>    <li>     <div style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">Check if they are necessary. Perhaps it is only there to support 1 batch process which might be better done via SQLCMD, Powershell or SSIS Workflow.</span> </div>   </li> </ul>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle">&#160;</p>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><u><span style="font-family: calibri; font-size: 11pt">Replication Filter Procedures</span> </u></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt; vertical-align: middle">This gives you a hint that you need to think about the replication system &amp; interop with other SQL databases. </p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt; vertical-align: middle">&#160;</p>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><u><span style="font-family: calibri; font-size: 11pt">CLR Objects</span> </u></p>  <ul>   <li>     <div style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">Lets you know if they are being used. </span></div>   </li>    <li>     <div style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">They can be extremely powerful especially to enhance string manipulation. </span></div>   </li>    <li>     <div style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">These are not used by many people. Typically they are only suggested by DBA's with an extensive knowledge of the entire feature set of SQL Server &amp; fairly good programming skills. So generally the DB design will be sound, there will be no easy wins &amp; you will need to work hard to prove your value.</span> </div>   </li> </ul>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle">&#160;</p>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><u><span style="font-family: calibri; font-size: 11pt">Plan Guides</span> </u></p>  <ul>   <li>     <div style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">Again these are an advanced feature. Anyone who created them would need to be extremely<span style="mso-spacerun: yes">&#160; </span>familiar with query plan optimisation. Thus you will need to think hard about any changes you make. </span></div>   </li> </ul>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt"><font color="#0000ff"></font></span></p>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt"><font color="#0000ff">As always I’m interested in any thoughts &amp; suggestions you may have </font></span></p>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt"><font color="#0000ff">Dave</font></span></p>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">&#160;</span></p>  <p><strong><u><font size="2" face="Tahoma">Random Thought for the post:</font></u></strong></p>  <blockquote>   <p><font size="2" face="Tahoma">“Look before you leap” might be good advice. But it is unlikely to be a great legal defence if police catch you hanging off the roof, staring into the change room window at the local public pool.</font></p></blockquote>]]></content:encoded>
    </item>
    <item>
      <title>"How To": Performance Tuning - High Frequency Queries - Test Harness</title>
      <link>https://docs.microsoft.com/archive/blogs/davidlean/how-to-performance-tuning-high-frequency-queries-test-harness</link>
      <pubDate>Sun, 24 Oct 2010 05:05:00 GMT</pubDate>
      <dc:creator><![CDATA[davele]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/davidlean/2010/10/24/how-to-performance-tuning-high-frequency-queries-test-harness/</guid>
      <description><![CDATA[&#160; If I had a month free I’d like to do a brain dump on how to Load Test, Bulk Up data, find...]]></description>
      <content:encoded><![CDATA[&#160; <p style="margin: 0in; font-family: calibri; color: #333333; font-size: 11pt">If I had a month free I’d like to do a brain dump on how to Load Test, Bulk Up data, find problem queries, refactor them with confidence etc. Then deliver it in one comprehensive guide. But that is unlikely, so I’ve decided to deliver little bits at a time then write an index to pull it all together if I ever finish.    <br /></p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt"><span style="color: #333333"></span></p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt"><span style="color: #333333">In this post I’ll start with the really obvious. </span>Often there you can think of multiple coding alternatives that yield the same answer. How do you know which code construct is the most efficient?<span style="mso-spacerun: yes">&#160; </span>This post offers one technique to help you determine that. </p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin: 0in; font-family: calibri; color: #333333; font-size: 11pt">It is useful when comparing<span style="mso-spacerun: yes">&#160; </span>different approaches to those High Frequency – Low Impact queries. By that I mean, comparing queries that by themselves really don’t take long, but they are run so often that they begin to represent a significant portion of the load on your system. Another area of use is, testing a code construct in a Select List that might be executed once for each row, in a billion row update they can really influence the time to complete the query. </p>  <p style="margin: 0in; font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt; font-weight: bold; text-decoration: underline">For Example</p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt">One of the columns in your select statement must display a cheque number with 10 digits. Eg: 1,234,567 displays as 0001234567. So you need to append leading zeros if your integer contains fewer than 10 digits.<span style="mso-spacerun: yes">&#160; </span>Which approach should you use?</p>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">1.&#160; Convert your int to a string, Find the length of the string. Subtract the length from 10 &amp; pre-pend that many zeros.</span> </p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: fuchsia">SUBSTRING</span><span style="color: gray">(</span><span style="color: red">'0000000000'</span><span style="color: gray">,</span> 1<span style="color: gray">,</span> 10 <span style="color: gray">-</span> <span style="color: fuchsia">LEN</span><span style="color: gray">(</span><span style="color: fuchsia">CAST</span><span style="color: gray">(</span>@ChequeID <span style="color: blue">AS</span> <span style="color: blue">varchar</span><span style="color: gray">(</span>10<span style="color: gray">))))</span> <span style="color: gray">+</span> <span style="color: fuchsia">CAST</span><span style="color: gray">(</span>@ChequeID <span style="color: blue">AS</span> <span style="color: blue">varchar</span><span style="color: gray">(</span>10<span style="color: gray">))</span></p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">&#160;</p>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">2.&#160; Convert your int to a string, Prepend 10 zeros. Then take the Rightmost 10 chars.</span> </p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: gray">RIGHT(</span> <span style="color: red">'0000000000'</span> <span style="color: gray">+</span> <span style="color: fuchsia">CAST</span><span style="color: gray">(</span>@ChequeID <span style="color: blue">AS</span> <span style="color: blue">varchar</span><span style="color: gray">(</span>10<span style="color: gray">)),</span> 10<span style="color: gray">)</span></p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">&#160;</p>  <p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">3.&#160; Same as Approach 1 but test to see if the Integer converts to exactly 10 digits &amp; only do the Substring manipulation when you have less than 10 digits.</span> </p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">CASE</span> <span style="color: blue">WHEN</span> <span style="color: fuchsia">LEN</span><span style="color: gray">(</span><span style="color: fuchsia">CAST</span><span style="color: gray">(</span>@ChequeID <span style="color: blue">AS</span> <span style="color: blue">varchar</span><span style="color: gray">(</span>10<span style="color: gray">)))</span> <span style="color: gray">&lt;</span> 10 </p>  <p style="margin: 0in 0in 0in 1.125in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">THEN</span> <span style="color: fuchsia">SUBSTRING</span><span style="color: gray">(</span><span style="color: red">'0000000000'</span><span style="color: gray">,</span> 1<span style="color: gray">,</span> 10 <span style="color: gray">-</span> <span style="color: fuchsia">LEN</span><span style="color: gray">(</span><span style="color: fuchsia">CAST</span><span style="color: gray">(</span>@ChequeID <span style="color: blue">AS</span> <span style="color: blue">varchar</span><span style="color: gray">(</span>10<span style="color: gray">))))</span> <span style="color: gray">+</span> <span style="color: fuchsia">CAST</span><span style="color: gray">(</span>@ChequeID <span style="color: blue">AS</span> <span style="color: blue">varchar</span><span style="color: gray">(</span>10<span style="color: gray">))</span> </p>  <p style="margin: 0in 0in 0in 1.125in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">ELSE</span> <span style="color: fuchsia">CAST</span><span style="color: gray">(</span>@ChequeID <span style="color: blue">AS</span> <span style="color: blue">varchar</span><span style="color: gray">(</span>10<span style="color: gray">))</span></p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">END</p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt"><span style="font-weight: bold; text-decoration: underline">Note:</span> </p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt">From a practical point of view you may think &quot;OK, this is trivial stuff, after all there is only a few milliseconds difference anyway&quot;. </p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt; text-decoration: underline">Answer 1</p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt">You may be correct, a good index is likely to be far more important. But remember, multi-table joins can generate millions of rows before they are filtered by the where clause. Saving a few seconds CPU time on each query can have a cumulative effect on overall system performance. </p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt">It may not be a huge win, but if it takes just as long to write inefficient code as it does to write more efficient code. Why not learn which code constructs are more efficient?</p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt; text-decoration: underline">Answer 2</p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt">Try looking at the difference when you call a User Function from your select list. It can make your query 50 times slower. Sometimes performance differences can be massive, these code alternatives can occasionally be much more important than an index.</p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Segoe UI&#39;"><span style="color: #333333; font-size: 10pt">     <br /></span><span style="color: blue; font-size: 12pt; font-weight: bold; text-decoration: underline"></span></p>  <h2><span style="color: blue; font-size: 12pt; font-weight: bold; text-decoration: underline">The basics</span></h2>  <p style="margin: 0in 0in 0in 0.375in; color: #333333"><span style="font-family: &#39;Segoe UI&#39;; font-size: 10pt"><span style="mso-spacerun: yes"></span>      <br /></span><span style="font-family: calibri; font-size: 11pt">For queries that are executed very frequently (High frequency queries), the normal approaches like “SET STATISTICS IO ON” &amp; “SET STATISTICS TIME ON” are inadequate. You get thousands of rows of output all saying “0 ms”. So I’ve reverted back to creating a loop, executing the test many times then comparing the time at the start &amp; end of the loop. </span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt; text-decoration: underline">Simple code example</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Segoe UI&#39;; font-size: 10pt"><span style="color: green">-- ---&lt; Template Testing Loop code &gt;---      <br /></span><span style="color: blue">DECLARE </span><span style="color: #333333">@cntLoop </span><span style="color: blue">INT</span><span style="color: gray">;<span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span></span><span style="color: blue">SET </span><span style="color: #333333">@cntLoop </span><span style="color: gray">= </span><span style="color: #333333">1      <br /></span><span style="color: blue">DECLARE </span><span style="color: #333333">@StartTime </span><span style="color: blue">DATETIME</span><span style="color: gray">; </span><span style="color: blue">SET </span><span style="color: #333333">@StartTime </span><span style="color: gray">= </span><span style="color: fuchsia">GETDATE</span><span style="color: gray">()      <br />      <br /></span><span style="color: blue">WHILE </span><span style="color: #333333">@cntLoop </span><span style="color: gray">&lt; </span><span style="color: #333333">1000 </span><span style="color: blue">BEGIN      <br />      <br /><span style="mso-spacerun: yes">&#160;&#160;&#160; </span></span><span style="color: green">-- &lt; Insert your test code here &gt;      <br />      <br /><span style="mso-spacerun: yes">&#160;&#160;&#160; </span></span><span style="color: blue">SET </span><span style="color: #333333">@cntLoop </span><span style="color: gray">= </span><span style="color: #333333">@cntLoop </span><span style="color: gray">+ </span><span style="color: #333333">1      <br /></span><span style="color: blue">END      <br />SELECT </span><span style="color: fuchsia">DATEDIFF</span><span style="color: gray">(</span><span style="color: #333333">ms</span><span style="color: gray">, </span><span style="color: #333333">@StartTime</span><span style="color: gray">, </span><span style="color: fuchsia">GETDATE</span><span style="color: gray">() ) </span><span style="color: blue">AS </span><span style="color: red">'Test Description Here (ms)'</span><span style="color: gray">;      <br /></span><span style="color: blue">Go</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; color: #333333"><span style="font-family: calibri; font-size: 11pt">(NB: If you think the layout of the DECLARE - SET looks odd, I converted the 2008 code back to 2005. In 2005 it is milliseconds faster to Declare all variables in one statement separated by commas. Then set them all in a single SELECT Statement. In 2008 you can Declare &amp; Initialise on the same line. So for readability I've used the SQL 2008 layout but in SQL2005 compatible syntax.)</span><span style="font-family: &#39;Segoe UI&#39;; font-size: 10pt">      <br /></span></p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>  <h2><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 12pt; font-weight: bold; text-decoration: underline">Taking a Baseline</span><span style="font-family: calibri; color: blue; font-size: 11pt; text-decoration: underline"></span></h2> <span style="font-family: calibri; color: blue; font-size: 11pt; text-decoration: underline"></span>  <p style="margin: 0in"><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 12pt; font-weight: bold; text-decoration: underline"></span><span style="font-family: calibri; color: blue; font-size: 11pt; text-decoration: underline"></span><span style="font-family: calibri; color: #333333; font-size: 11pt">Unlike </span><a href="https://en.wikipedia.org/wiki/Werner_Heisenberg"><span style="font-family: calibri; font-size: 11pt">Heisenberg</span></a><span style="font-family: calibri; color: #333333; font-size: 11pt"> we can &amp; should adjust for the overhead of our measuring equipment. So at a minimum we should run 3 tests :-</span></p>  <p style="margin-top: 0px; margin-bottom: 0px; color: #333333; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">1. The test loop with <strong>nothing</strong> inside. </span></p>  <p style="margin-top: 0px; margin-bottom: 0px; color: #333333; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">2. The test loop with our <strong>orignial</strong> TSQL code. </span></p>  <p style="margin-top: 0px; margin-bottom: 0px; color: #333333; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">3. The test loop with our hopefully <strong>faster</strong> TSQL code. </span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; color: #333333; font-size: 11pt">   <br />That way we can subtract time it takes to run the test “doing nothing” from the other 2 runs in order to really understand the percentage improvement between our alternatives. </p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt; text-decoration: underline">Example - Measure the overhead of your looping code</p>  <p style="margin: 0in 0in 0in 0.375in"><span style="font-family: calibri; color: #333333; font-size: 11pt">NB: To make it easier to manage multiple tests I use a SQLCMD Variable to set the maximum Iterations.</span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">      <br /></span><span style="font-family: &#39;Segoe UI&#39;; color: green; font-size: 10pt">-- =========================================================================================      <br />-- Test Harness to compare impact of small High Frequency Operations &amp;/or Things called once for each row in a query.       <br />-- Method: Remember to subtract the overhead of the Test Harness from each result.       <br />--<span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>Remember to Click &quot;Menu: Query-&gt;SQLCMD mode&quot; or the SETVAR MAXLOOPS line will give you an error.       <br />-- =========================================================================================       <br />-- Change this value to impact the duration of ALL tests.       <br /></span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">:SETVAR MAXLOOPS 2000000      <br />      <br /></span><span style="font-family: &#39;Segoe UI&#39;; color: green; font-size: 10pt">-- =========================================================================================      <br />-- ---&lt; Pre-Test: Calculate Overhead of Looping code &gt;---       <br /></span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">DECLARE </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@cntLoop </span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">INT</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">;<span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span></span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">SET </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@cntLoop </span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">= </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">1      <br /></span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">DECLARE </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@StartTime </span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">DATETIME</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">; </span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">SET </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@StartTime </span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">= </span><span style="font-family: &#39;Segoe UI&#39;; color: fuchsia; font-size: 10pt">GETDATE</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">()      <br /></span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">DECLARE </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@Result </span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">VARCHAR</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">(</span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">8</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">); </span><span style="font-family: &#39;Segoe UI&#39;; color: green; font-size: 10pt">-- or whatever data type your test returns.      <br />      <br /></span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">WHILE </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@cntLoop </span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">&lt; </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">$</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">(</span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">MAXLOOPS</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">) </span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">BEGIN      <br />      <br /><span style="mso-spacerun: yes">&#160;&#160;&#160; </span>SELECT </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@Result </span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">= </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">1 </span><span style="font-family: &#39;Segoe UI&#39;; color: green; font-size: 10pt">-- Empty assignment      <br />      <br /><span style="mso-spacerun: yes">&#160;&#160;&#160; </span></span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">SET </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@cntLoop </span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">= </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@cntLoop </span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">+ </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">1      <br /></span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">END      <br />SELECT </span><span style="font-family: &#39;Segoe UI&#39;; color: fuchsia; font-size: 10pt">DATEDIFF</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">(</span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">ms</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">, </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@StartTime</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">, </span><span style="font-family: &#39;Segoe UI&#39;; color: fuchsia; font-size: 10pt">GETDATE</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">() ) </span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">AS </span><span style="font-family: &#39;Segoe UI&#39;; color: red; font-size: 10pt">'Empty MAXLOOPS Overhead'</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">;      <br /></span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">go      <br />      <br /></span><span style="font-family: &#39;Segoe UI&#39;; color: green; font-size: 10pt">-- =========================================================================================      <br />-- ---&lt; Test 1: Calculate Overhead of Calling existing User Function &gt;---       <br /></span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">DECLARE </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@cntLoop </span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">INT</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">;<span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span></span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">SET </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@cntLoop </span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">= </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">1      <br /></span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">DECLARE </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@StartTime </span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">DATETIME</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">; </span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">SET </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@StartTime </span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">= </span><span style="font-family: &#39;Segoe UI&#39;; color: fuchsia; font-size: 10pt">GETDATE</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">()      <br /></span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">DECLARE </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@Result </span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">VARCHAR</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">(</span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">8</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">); </span><span style="font-family: &#39;Segoe UI&#39;; color: green; font-size: 10pt">-- or whatever data type your test returns.      <br />      <br /></span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">WHILE </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@cntLoop </span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">&lt; </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">$</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">(</span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">MAXLOOPS</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">) </span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">BEGIN      <br />      <br /><span style="mso-spacerun: yes">&#160;&#160;&#160; </span></span><span style="font-family: &#39;Segoe UI&#39;; color: green; font-size: 10pt">-- Orignial version      <br /><span style="mso-spacerun: yes">&#160;&#160;&#160; </span></span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">SELECT </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@Result </span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">= </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">[dbo]</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">.</span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">[uf_MinutestoStringTime] </span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">(</span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@cntLoop</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">)      <br />      <br /><span style="mso-spacerun: yes">&#160;&#160;&#160; </span></span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">SET </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@cntLoop </span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">= </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@cntLoop </span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">+ </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">1      <br /></span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">END      <br />SELECT </span><span style="font-family: &#39;Segoe UI&#39;; color: fuchsia; font-size: 10pt">DATEDIFF</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">(</span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">ms</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">, </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@StartTime</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">, </span><span style="font-family: &#39;Segoe UI&#39;; color: fuchsia; font-size: 10pt">GETDATE</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">() ) </span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">AS </span><span style="font-family: &#39;Segoe UI&#39;; color: red; font-size: 10pt">'Original'</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">;      <br /></span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">go      <br />      <br /></span><span style="font-family: &#39;Segoe UI&#39;; color: green; font-size: 10pt">-- =========================================================================================      <br />-- ---&lt; Test 2: Calculate Overhead of Calling &quot;New Improved&quot; Function &gt;---       <br />-- My results show this takes ~4% of Original ie: 25 Times faster. (or whatever you got)       <br /></span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">DECLARE </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@cntLoop </span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">INT</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">;<span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span></span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">SET </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@cntLoop </span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">= </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">1      <br /></span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">DECLARE </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@StartTime </span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">DATETIME</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">; </span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">SET </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@StartTime </span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">= </span><span style="font-family: &#39;Segoe UI&#39;; color: fuchsia; font-size: 10pt">GETDATE</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">()      <br /></span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">DECLARE </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@Result </span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">VARCHAR</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">(</span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">8</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">); </span><span style="font-family: &#39;Segoe UI&#39;; color: green; font-size: 10pt">-- or whatever data type your test returns.      <br />      <br /></span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">WHILE </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@cntLoop </span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">&lt; </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">$</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">(</span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">MAXLOOPS</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">) </span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">BEGIN      <br />      <br /><span style="mso-spacerun: yes">&#160;&#160;&#160; </span></span><span style="font-family: &#39;Segoe UI&#39;; color: green; font-size: 10pt">-- Refactored Improved version      <br /><span style="mso-spacerun: yes">&#160;&#160;&#160; </span></span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">SELECT </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@Result </span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">= </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">[dbo]</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">.</span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">[uf_MinutestoStringTime2] </span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">(</span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@cntLoop</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">)      <br />      <br /><span style="mso-spacerun: yes">&#160;&#160;&#160; </span></span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">SET </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@cntLoop </span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">= </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@cntLoop </span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">+ </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">1      <br /></span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">END      <br />SELECT </span><span style="font-family: &#39;Segoe UI&#39;; color: fuchsia; font-size: 10pt">DATEDIFF</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">(</span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">ms</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">, </span><span style="font-family: &#39;Segoe UI&#39;; color: #333333; font-size: 10pt">@StartTime</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">, </span><span style="font-family: &#39;Segoe UI&#39;; color: fuchsia; font-size: 10pt">GETDATE</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">() ) </span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">AS </span><span style="font-family: &#39;Segoe UI&#39;; color: red; font-size: 10pt">'Refactored to use Set functions'</span><span style="font-family: &#39;Segoe UI&#39;; color: gray; font-size: 10pt">;      <br /></span><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-size: 10pt">go      <br /></span><span style="font-family: &#39;Segoe UI&#39;; color: green; font-size: 10pt">-- =========================================================================================</span></p>  <p style="margin: 0in 0in 0in 0.75in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: calibri; font-size: 11pt">&#160;</p>  <h2><font color="#0000ff" size="3" face="Segoe UI"><u>Factor in the random crap</u></font></h2>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; color: #333333; font-size: 11pt">Of course the universe will gang up on you to ensure your results are meaningless. </p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; color: #333333; font-size: 11pt">&#160;</p>  <ul style="margin-top: 0in; unicode-bidi: embed; direction: ltr; margin-bottom: 0in; margin-left: 0.375in" type="circle">   <li style="margin-top: 0px; margin-bottom: 0px; color: #333333; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">Clearly it is best if you can run it in a way to </span><span style="font-family: calibri; font-size: 11pt; font-weight: bold">avoid load from others</span><span style="font-family: calibri; font-size: 11pt">. Perhaps on a machine where you are the only user. eg: your workstation or a test server or after hours. But even then you are never alone, all sorts of background threads &amp; tasks are going to partially impact a test run. eg: A SQL Checkpoint process could completely overlap just one of the tests &amp; not the other. The SQL log may run out of space &amp; need to be expanded in the middle of your test. etc</span> </li> </ul>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; color: #333333; font-size: 11pt">&#160;</p>  <ul style="margin-top: 0in; unicode-bidi: embed; direction: ltr; margin-bottom: 0in; margin-left: 0.375in" type="circle">   <li style="margin-top: 0px; margin-bottom: 0px; color: #333333; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">Another bugger factor is that</span><span style="font-family: calibri; font-size: 11pt; font-weight: bold"> Windows is interrupt driven</span><span style="font-family: calibri; font-size: 11pt">, at least every 15ms. (well on x86 PC architectures anyway). Your test could be paused while something else runs. So the smaller the timeframe the greater potential for statistical error. But as mentioned in the prior paragraph, if you loop more times, the longer the timeframe of the tests, the greater potential for impact via other threads.</span> </li> </ul>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt">&#160;</p>  <ul style="margin-top: 0in; unicode-bidi: embed; direction: ltr; margin-bottom: 0in; margin-left: 0.375in" type="circle">   <li style="margin-top: 0px; margin-bottom: 0px; color: #333333; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">Another pain is that the test you try first</span><span style="font-family: calibri; font-size: 11pt; font-weight: bold"> </span><span style="font-family: calibri; font-size: 11pt">could</span><span style="font-family: calibri; font-size: 11pt; font-weight: bold"> warm up the cache or environment</span><span style="font-family: calibri; font-size: 11pt"> &amp; somehow assist the test that runs second. Making it look faster than it really is. Sure you could Free buffers &amp;/or stop &amp; restart the SQL Instance each time, but that slows you down &amp; is probably not typical of the hot environment your queries will most likely be running in. </span></li> </ul>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt">&#160;</p>  <blockquote>   <h6><u><font size="3">So some of the ways you can minimise errors are:-</font></u></h6> </blockquote>  <ol>   <li>     <div style="margin-top: 0px; margin-bottom: 0px; color: #333333; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">In the same test run, run each test more than once. I usually run 6 tests:-          <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; a) Test Harness<span style="mso-spacerun: yes">&#160; </span>(for the baseline)           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; b) Test A           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; c) Test B           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; d) Test B (again)           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; e) Test A (again)           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; f) Test Harness (again)           <br />That way you can check that each of the 3 tests deliver similar results in both executions. If they don’t, the entire test run is invalid. (Or at least can’t be reliably extrapolated) </span></div>   </li>    <li>     <div style="margin-top: 0px; margin-bottom: 0px; color: #333333; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">Like all good statisticians. Run the test group a few times. 30 would be a statistically good number, but 5 is probably adequate especially if each run is giving similar results. </span></div>   </li>    <li>     <div style="margin-top: 0px; margin-bottom: 0px; color: #333333; vertical-align: middle"><span style="font-family: calibri; color: #333333; font-size: 11pt"> If you can &amp; it is important enough for you. Remember to try it on multiple machines.          <br />CPU &amp; Memory Access speeds often vary between machine &amp; I have seen coding alternatives which are dramatically different on one machine be not as dramatic on another. (but usually there is a clear winner everywhere or there was only a negligible 1-3% difference anywhere.)           <br /></span><span style="font-family: calibri; color: black; font-size: 11pt">Especially important is different disk capacities. While this type of testing is less useful for I/O int</span><span style="font-family: calibri; color: #333333; font-size: 11pt">ensive queries, I don't know what you will be doing so maybe you need to think about it.          <br /></span></div>   </li> </ol>  <p style="margin: 0in 0in 0in 0.75in; font-family: calibri; font-size: 11pt; font-weight: bold">Example Results</p>  <p style="margin: 0in 0in 0in 1.125in; font-family: calibri; font-size: 11pt">These were obtained from running the 10 digit leading zero tests mentioned above.</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin: 0in 0in 0in 1.125in"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/8030.clip_image001[4].png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/8030.clip_5F00_image001_5B00_4_5D00_.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Example of Analysisng the Results in Excel" border="0" alt="Example of Analysisng the Results in Excel" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/8424.clip_image001[4]_thumb.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/8424.clip_5F00_image001_5B00_4_5D005F00_thumb.png" width="244" height="79" /></a></p>  <p style="margin: 0in 0in 0in 1.125in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin: 0in 0in 0in 1.125in; font-family: calibri; font-size: 11pt">In the above you can see the raw results in Columns B-I. </p>  <p style="margin: 0in 0in 0in 1.125in; font-family: calibri; font-size: 11pt">Column J shows the difference between the two Right Append Tests (cols D &amp; G)</p>  <p style="margin: 0in 0in 0in 1.125in; font-family: calibri; font-size: 11pt">Cols N - Q shows the % change between each of the similar tests in that run. Where 100% is No difference. Anything greater or lower is bad.</p>  <p style="margin: 0in 0in 0in 1.125in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin: 0in 0in 0in 1.125in; font-family: calibri; font-size: 11pt">While I'm not really happy with the huge variation within each test run, it is sufficient to make a decision. It is easy to see the difference between each type of test is even more dramatic than the margin of error in each test.<span style="mso-spacerun: yes">&#160; </span>So it is reasonable to conclude that the &quot;Right()&quot; approach is more efficient than the &quot;Substring()&quot; technique. And any benefit you thought you'd get by using a case to avoid any unnecessary substring commands is a waste of time.</p>  <p style="margin: 0in 0in 0in 1.125in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin: 0in 0in 0in 1.125in; font-family: calibri; color: blue; font-size: 11pt; font-weight: bold">Bonus TIP:</p>  <p style="margin: 0in 0in 0in 1.125in; font-family: calibri; font-size: 11pt">These results are consistent with every TSQL test I've done. In TSQL there is no point testing to see if an operation needs to occur &amp; then doing it. Just do it to all rows.</p>  <p style="margin: 0in 0in 0in 1.125in; font-family: calibri; font-size: 11pt">For example this query is slower</p>  <p style="margin: 0in 0in 0in 1.125in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: blue">CASE</span> <span style="color: blue">WHEN</span> LastName <span style="color: gray">IS</span> <span style="color: gray">NOT</span> <span style="color: gray">NULL</span> <span style="color: blue">THEN</span> <span style="color: fuchsia">UPPER</span><span style="color: gray">(</span>LastName<span style="color: gray">)</span> <span style="color: blue">END</span> <span style="color: blue">As</span> Lastname</p>  <p style="margin: 0in 0in 0in 1.125in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">FROM</span> Custs</p>  <p style="margin: 0in 0in 0in 1.125in; font-family: &#39;Courier New&#39;; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 1.125in; font-family: calibri; font-size: 11pt">than this query. The UPPPER() function is perfectly capable of dealing with NULL's.</p>  <p style="margin: 0in 0in 0in 1.125in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: fuchsia">UPPER</span><span style="color: gray">(</span>LastName<span style="color: gray">)</span> <span style="color: blue">As</span> Lastname</p>  <p style="margin: 0in 0in 0in 1.125in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">FROM</span> Custs</p>  <p style="margin: 0in 0in 0in 1.125in; font-family: calibri; font-size: 11pt">On my machine the later took 100 units of time &amp; the former (with the CASE statement) took 187 Units. Ie 87% slower.</p>  <p style="margin: 0in 0in 0in 1.125in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: calibri; color: #333333; font-size: 11pt">&#160;</p>  <h3><font size="3"><font face="Segoe UI"><span style="font-weight: bold; text-decoration: underline">Template Loop Code</span>:</font></font></h3>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt">This code is extended slightly from the basic example above. Showing setting any other variables you may need in your test. Together with an improved way to view the results of the query. If you don't assign them to a variable they will be returned to the screen (or calling app), this will slow your test.</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in"><span style="font-family: calibri; font-size: 11pt">You will note the </span><span style="font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">:</span><span style="font-family: &#39;Courier New&#39;; font-size: 10pt">SETVAR </span><span style="font-family: calibri; font-size: 11pt">this lets me refer to a variable with a life beyond each batch. So remember to enable SQLCMD in SSMS. Eg: Menu: Query =&gt; SQLCMD Mode.</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt">Changing this value will increase / decrease the length of each test. As Windows timer is in 15 ms chunks, it is best to adjust this so that each test runs for at least several seconds.</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Set Test Loop Counter &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: gray">:</span>SETVAR LOOPCNT 100000 <span style="color: green">-- &lt; How many times each test will be repeated. </span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ===&lt; Empty Test: Measure Test Harness overhead &gt;==============</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Set Test Specific Variables &gt;---</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @CommSourceID <span style="color: blue">BIGINT</span><span style="color: gray">;</span> <span style="color: blue">SELECT</span> @CommSourceID <span style="color: gray">=</span> <span style="color: red">'1234567'</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: red; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Set Harness Variables &gt;---</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @Results <span style="color: blue">VARCHAR</span><span style="color: gray">(</span>20<span style="color: gray">)</span></p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @cnt <span style="color: blue">INT</span><span style="color: gray">;</span><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">SET</span> @cnt <span style="color: gray">=</span> 0</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @StartTime <span style="color: blue">DATETIME</span><span style="color: gray">;</span> <span style="color: blue">SET</span> @StartTime <span style="color: gray">=</span> <span style="color: fuchsia">GETDATE</span><span style="color: gray">()</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Execute Test many times &gt;---</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHILE</span> @cnt <span style="color: gray">&lt;</span> $<span style="color: gray">(</span>LOOPCNT<span style="color: gray">)</span></p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">BEGIN</p>  <p style="margin: 0in 0in 0in 1.125in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Insert your Test Query Below here &gt;---</p>  <p style="margin: 0in 0in 0in 1.125in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- &lt; do nothing here - empty test &gt;</p>  <p style="margin: 0in 0in 0in 1.125in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Insert your Test Query Above here &gt;---</p>  <p style="margin: 0in 0in 0in 1.125in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> @cnt <span style="color: gray">=</span> @cnt <span style="color: gray">+</span> 1<span style="color: gray">;</span></p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">END</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Display Test Results &gt;---</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: fuchsia">DATEDIFF</span><span style="color: gray">(</span>ms<span style="color: gray">,</span> @StartTime<span style="color: gray">,</span> <span style="color: fuchsia">GETDATE</span><span style="color: gray">())</span> <span style="color: blue">AS</span> Duration_ms</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: gray">,</span>@Results <span style="color: blue">AS</span> <span style="color: red">'Empty Harness 1'</span> <span style="color: green">-- &lt;&lt; Meaningful label for test</span></p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">GO</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt">I also like to display the value returned by my query (ie:@Results) this is a sanity check just to ensure that the codes snippets do actually return identical code. I realise this is only displaying the last value assigned &amp; every value assigned in prior iterations of the loop were overwritten. Normally this would be bad, in this case I don't care, they should all be identical. </p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>  <h5><font size="3" face="Segoe UI"><u>Sample Code to test the 3 alternatives discussed in the introduction</u></font></h5>  <p style="margin: 0in; font-family: calibri; font-size: 11pt">Use this as your template.</p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">/* ===========================================================</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">** TEST HARNESS for small high frequency tests.</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">** eg: TSQL run for every row in a large query.</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">** Notes: Before reaching any conclusion. </p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">** 1. You should repeat these tests at least 5 times</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">**<span style="mso-spacerun: yes">&#160;&#160;&#160; </span>&amp; ensure the variance between each run is small.</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">** 2. You need to mirror the tests components </p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">**<span style="mso-spacerun: yes">&#160;&#160;&#160; </span>ie: Harness, Test A, Test B, Test B, Test A, Harness.</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">**<span style="mso-spacerun: yes">&#160;&#160;&#160; </span>Then check if Harness = Harness, Test A = Test A, etc </p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">**<span style="mso-spacerun: yes">&#160;&#160;&#160; </span>If not then the Test Run would likely to be adversely impacted by something.</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">** 3. It is safer to push the Test Output into a variable then to the screen. </p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">**<span style="mso-spacerun: yes">&#160;&#160;&#160; </span>This removes delay caused but network &amp; client.</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">** 4. This uses Old-Style Variable initialisation to ensure it works on pre-SQL2008</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">** 5. Ensure SQLCMD mode = ON </p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">** ===========================================================</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">*/</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">SET NOCOUNT ON</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Set Test Loop Counter &gt;---</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: gray">:</span>SETVAR LOOPCNT 100000 <span style="color: green">-- &lt; How many times each test will be repeated. </span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ===&lt; Empty Test: Measure Test Harness overhead &gt;==============</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Set Test Specific Variables &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @CommSourceID <span style="color: blue">BIGINT</span><span style="color: gray">;</span> <span style="color: blue">SELECT</span> @CommSourceID <span style="color: gray">=</span> <span style="color: red">'1234567'</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: red; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Set Harness Variables &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @Results <span style="color: blue">VARCHAR</span><span style="color: gray">(</span>20<span style="color: gray">)</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @cnt <span style="color: blue">INT</span><span style="color: gray">;</span><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">SET</span> @cnt <span style="color: gray">=</span> 0</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @StartTime <span style="color: blue">DATETIME</span><span style="color: gray">;</span> <span style="color: blue">SET</span> @StartTime <span style="color: gray">=</span> <span style="color: fuchsia">GETDATE</span><span style="color: gray">()</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Execute Test many times &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHILE</span> @cnt <span style="color: gray">&lt;</span> $<span style="color: gray">(</span>LOOPCNT<span style="color: gray">)</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">BEGIN</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Insert your Test Query Below here &gt;---</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- &lt; do nothing here - empty test &gt;</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Insert your Test Query Above here &gt;---</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> @cnt <span style="color: gray">=</span> @cnt <span style="color: gray">+</span> 1<span style="color: gray">;</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">END</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Display Test Results &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: fuchsia">DATEDIFF</span><span style="color: gray">(</span>ms<span style="color: gray">,</span> @StartTime<span style="color: gray">,</span> <span style="color: fuchsia">GETDATE</span><span style="color: gray">())</span> <span style="color: blue">AS</span> Duration_ms</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: gray">,</span>@Results <span style="color: blue">AS</span> <span style="color: red">'Empty Harness 1'</span> <span style="color: green">-- &lt;&lt; Meaningful label for test</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">GO</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ===&lt; TEST A: 1st Run &gt;==============</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Set Test Specific Variables &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @CommSourceID <span style="color: blue">BIGINT</span><span style="color: gray">;</span> <span style="color: blue">SELECT</span> @CommSourceID <span style="color: gray">=</span> <span style="color: red">'1234567'</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: red; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Set Harness Variables &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @Results <span style="color: blue">VARCHAR</span><span style="color: gray">(</span>20<span style="color: gray">)</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @cnt <span style="color: blue">INT</span><span style="color: gray">;</span><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">SET</span> @cnt <span style="color: gray">=</span> 0</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @StartTime <span style="color: blue">DATETIME</span><span style="color: gray">;</span> <span style="color: blue">SET</span> @StartTime <span style="color: gray">=</span> <span style="color: fuchsia">GETDATE</span><span style="color: gray">()</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Execute Test many times &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHILE</span> @cnt <span style="color: gray">&lt;</span> $<span style="color: gray">(</span>LOOPCNT<span style="color: gray">)</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">BEGIN</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Insert your Test Query Below here &gt;---</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> @Results <span style="color: gray">=</span> <span style="color: fuchsia">SUBSTRING</span><span style="color: gray">(</span><span style="color: red">'0000000000'</span><span style="color: gray">,</span> 1<span style="color: gray">,</span> 10 <span style="color: gray">-</span> <span style="color: fuchsia">LEN</span><span style="color: gray">(</span><span style="color: fuchsia">CAST</span><span style="color: gray">(</span>@CommSourceID <span style="color: blue">AS</span> <span style="color: blue">varchar</span><span style="color: gray">(</span>10<span style="color: gray">))))</span> <span style="color: gray">+</span> <span style="color: fuchsia">CAST</span><span style="color: gray">(</span>@CommSourceID <span style="color: blue">AS</span> <span style="color: blue">varchar</span><span style="color: gray">(</span>10<span style="color: gray">))</span> </p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Insert your Test Query Above here &gt;---</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> @cnt <span style="color: gray">=</span> @cnt <span style="color: gray">+</span> 1<span style="color: gray">;</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">END</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Display Test Results &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: fuchsia">DATEDIFF</span><span style="color: gray">(</span>ms<span style="color: gray">,</span> @StartTime<span style="color: gray">,</span> <span style="color: fuchsia">GETDATE</span><span style="color: gray">())</span> <span style="color: blue">AS</span> Duration_ms</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: gray">,</span>@Results <span style="color: blue">AS</span> <span style="color: red">'Substring Manipulation 1'</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">GO</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ===&lt; TEST B: 1st Run &gt;==============<span style="mso-spacerun: yes">&#160;&#160;&#160; </span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Set Test Specific Variables &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @CommSourceID <span style="color: blue">BIGINT</span><span style="color: gray">;</span> <span style="color: blue">SELECT</span> @CommSourceID <span style="color: gray">=</span> <span style="color: red">'1234567'</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: red; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Set Harness Variables &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @Results <span style="color: blue">VARCHAR</span><span style="color: gray">(</span>20<span style="color: gray">)</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @cnt <span style="color: blue">INT</span><span style="color: gray">;</span><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">SET</span> @cnt <span style="color: gray">=</span> 0</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @StartTime <span style="color: blue">DATETIME</span><span style="color: gray">;</span> <span style="color: blue">SET</span> @StartTime <span style="color: gray">=</span> <span style="color: fuchsia">GETDATE</span><span style="color: gray">()</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Execute Test many times &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHILE</span> @cnt <span style="color: gray">&lt;</span> $<span style="color: gray">(</span>LOOPCNT<span style="color: gray">)</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">BEGIN</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Insert your Test Query Below here &gt;---</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> @Results <span style="color: gray">=</span> <span style="color: gray">RIGHT(</span> <span style="color: red">'0000000000'</span> <span style="color: gray">+</span> <span style="color: fuchsia">CAST</span><span style="color: gray">(</span>@CommSourceID <span style="color: blue">AS</span> <span style="color: blue">varchar</span><span style="color: gray">(</span>10<span style="color: gray">)),</span> 10<span style="color: gray">)</span></p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Insert your Test Query Above here &gt;---</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> @cnt <span style="color: gray">=</span> @cnt <span style="color: gray">+</span> 1<span style="color: gray">;</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">END</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Display Test Results &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: fuchsia">DATEDIFF</span><span style="color: gray">(</span>ms<span style="color: gray">,</span> @StartTime<span style="color: gray">,</span> <span style="color: fuchsia">GETDATE</span><span style="color: gray">())</span> <span style="color: blue">AS</span> Duration_ms</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: gray">,</span>@Results <span style="color: blue">AS</span> <span style="color: red">'Right Append 1'</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">GO</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ===&lt; TEST C: 1st Run &gt;==============<span style="mso-spacerun: yes">&#160;&#160;&#160; </span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Set Test Specific Variables &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @CommSourceID <span style="color: blue">BIGINT</span><span style="color: gray">;</span> <span style="color: blue">SELECT</span> @CommSourceID <span style="color: gray">=</span> <span style="color: red">'1234567'</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: red; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Set Harness Variables &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @Results <span style="color: blue">VARCHAR</span><span style="color: gray">(</span>20<span style="color: gray">)</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @cnt <span style="color: blue">INT</span><span style="color: gray">;</span><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">SET</span> @cnt <span style="color: gray">=</span> 0</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @StartTime <span style="color: blue">DATETIME</span><span style="color: gray">;</span> <span style="color: blue">SET</span> @StartTime <span style="color: gray">=</span> <span style="color: fuchsia">GETDATE</span><span style="color: gray">()</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Execute Test many times &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHILE</span> @cnt <span style="color: gray">&lt;</span> $<span style="color: gray">(</span>LOOPCNT<span style="color: gray">)</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">BEGIN</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Insert your Test Query Below here &gt;---</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> @Results <span style="color: gray">=</span> <span style="color: blue">CASE</span> <span style="color: blue">WHEN</span> <span style="color: fuchsia">LEN</span><span style="color: gray">(</span><span style="color: fuchsia">CAST</span><span style="color: gray">(</span>@CommSourceID <span style="color: blue">AS</span> <span style="color: blue">varchar</span><span style="color: gray">(</span>10<span style="color: gray">)))</span> <span style="color: gray">&lt;</span> 10 </p>  <p style="margin: 0in 0in 0in 2.625in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">THEN</span> <span style="color: fuchsia">SUBSTRING</span><span style="color: gray">(</span><span style="color: red">'0000000000'</span><span style="color: gray">,</span> 1<span style="color: gray">,</span> 10 <span style="color: gray">-</span> <span style="color: fuchsia">LEN</span><span style="color: gray">(</span><span style="color: fuchsia">CAST</span><span style="color: gray">(</span>@CommSourceID <span style="color: blue">AS</span> <span style="color: blue">varchar</span><span style="color: gray">(</span>10<span style="color: gray">))))</span> <span style="color: gray">+</span> <span style="color: fuchsia">CAST</span><span style="color: gray">(</span>@CommSourceID <span style="color: blue">AS</span> <span style="color: blue">varchar</span><span style="color: gray">(</span>10<span style="color: gray">))</span> </p>  <p style="margin: 0in 0in 0in 2.625in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">ELSE</span> <span style="color: fuchsia">CAST</span><span style="color: gray">(</span>@CommSourceID <span style="color: blue">AS</span> <span style="color: blue">varchar</span><span style="color: gray">(</span>10<span style="color: gray">))</span> <span style="color: blue">END</span> <span style="color: green">--AS BarcodeNumber,</span></p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Insert your Test Query Above here &gt;---</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> @cnt <span style="color: gray">=</span> @cnt <span style="color: gray">+</span> 1<span style="color: gray">;</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">END</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Display Test Results &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: fuchsia">DATEDIFF</span><span style="color: gray">(</span>ms<span style="color: gray">,</span> @StartTime<span style="color: gray">,</span> <span style="color: fuchsia">GETDATE</span><span style="color: gray">())</span> <span style="color: blue">AS</span> Duration_ms</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: gray">,</span>@Results <span style="color: blue">AS</span> <span style="color: red">'CASE &amp; Substring 1'</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">GO</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ==============================================&lt; Repeat Tests in reverse order &gt;============== </p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ===&lt; TEST C: 2nd Run &gt;==============<span style="mso-spacerun: yes">&#160;&#160;&#160; </span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Set Test Specific Variables &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @CommSourceID <span style="color: blue">BIGINT</span><span style="color: gray">;</span> <span style="color: blue">SELECT</span> @CommSourceID <span style="color: gray">=</span> <span style="color: red">'1234567'</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: red; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Set Harness Variables &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @Results <span style="color: blue">VARCHAR</span><span style="color: gray">(</span>20<span style="color: gray">)</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @cnt <span style="color: blue">INT</span><span style="color: gray">;</span><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">SET</span> @cnt <span style="color: gray">=</span> 0</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @StartTime <span style="color: blue">DATETIME</span><span style="color: gray">;</span> <span style="color: blue">SET</span> @StartTime <span style="color: gray">=</span> <span style="color: fuchsia">GETDATE</span><span style="color: gray">()</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Execute Test many times &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHILE</span> @cnt <span style="color: gray">&lt;</span> $<span style="color: gray">(</span>LOOPCNT<span style="color: gray">)</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">BEGIN</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Insert your Test Query Below here &gt;---</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> @Results <span style="color: gray">=</span> <span style="color: blue">CASE</span> <span style="color: blue">WHEN</span> <span style="color: fuchsia">LEN</span><span style="color: gray">(</span><span style="color: fuchsia">CAST</span><span style="color: gray">(</span>@CommSourceID <span style="color: blue">AS</span> <span style="color: blue">varchar</span><span style="color: gray">(</span>10<span style="color: gray">)))</span> <span style="color: gray">&lt;</span> 10 </p>  <p style="margin: 0in 0in 0in 2.625in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">THEN</span> <span style="color: fuchsia">SUBSTRING</span><span style="color: gray">(</span><span style="color: red">'0000000000'</span><span style="color: gray">,</span> 1<span style="color: gray">,</span> 10 <span style="color: gray">-</span> <span style="color: fuchsia">LEN</span><span style="color: gray">(</span><span style="color: fuchsia">CAST</span><span style="color: gray">(</span>@CommSourceID <span style="color: blue">AS</span> <span style="color: blue">varchar</span><span style="color: gray">(</span>10<span style="color: gray">))))</span> <span style="color: gray">+</span> <span style="color: fuchsia">CAST</span><span style="color: gray">(</span>@CommSourceID <span style="color: blue">AS</span> <span style="color: blue">varchar</span><span style="color: gray">(</span>10<span style="color: gray">))</span> </p>  <p style="margin: 0in 0in 0in 2.625in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">ELSE</span> <span style="color: fuchsia">CAST</span><span style="color: gray">(</span>@CommSourceID <span style="color: blue">AS</span> <span style="color: blue">varchar</span><span style="color: gray">(</span>10<span style="color: gray">))</span> <span style="color: blue">END</span> <span style="color: green">--AS BarcodeNumber,</span></p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Insert your Test Query Above here &gt;---</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> @cnt <span style="color: gray">=</span> @cnt <span style="color: gray">+</span> 1<span style="color: gray">;</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">END</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Display Test Results &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: fuchsia">DATEDIFF</span><span style="color: gray">(</span>ms<span style="color: gray">,</span> @StartTime<span style="color: gray">,</span> <span style="color: fuchsia">GETDATE</span><span style="color: gray">())</span> <span style="color: blue">AS</span> Duration_ms</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: gray">,</span>@Results <span style="color: blue">AS</span> <span style="color: red">'CASE &amp; Substring 2'</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">GO</span> </p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="mso-spacerun: yes">&#160;&#160; </span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ===&lt; TEST B: 2nd Run &gt;==============<span style="mso-spacerun: yes">&#160;&#160;&#160; </span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Set Test Specific Variables &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @CommSourceID <span style="color: blue">BIGINT</span><span style="color: gray">;</span> <span style="color: blue">SELECT</span> @CommSourceID <span style="color: gray">=</span> <span style="color: red">'1234567'</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: red; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Set Harness Variables &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @Results <span style="color: blue">VARCHAR</span><span style="color: gray">(</span>20<span style="color: gray">)</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @cnt <span style="color: blue">INT</span><span style="color: gray">;</span><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">SET</span> @cnt <span style="color: gray">=</span> 0</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @StartTime <span style="color: blue">DATETIME</span><span style="color: gray">;</span> <span style="color: blue">SET</span> @StartTime <span style="color: gray">=</span> <span style="color: fuchsia">GETDATE</span><span style="color: gray">()</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Execute Test many times &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHILE</span> @cnt <span style="color: gray">&lt;</span> $<span style="color: gray">(</span>LOOPCNT<span style="color: gray">)</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">BEGIN</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Insert your Test Query Below here &gt;---</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> @Results <span style="color: gray">=</span> <span style="color: gray">RIGHT(</span> <span style="color: red">'0000000000'</span> <span style="color: gray">+</span> <span style="color: fuchsia">CAST</span><span style="color: gray">(</span>@CommSourceID <span style="color: blue">AS</span> <span style="color: blue">varchar</span><span style="color: gray">(</span>10<span style="color: gray">)),</span> 10<span style="color: gray">)</span></p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Insert your Test Query Above here &gt;---</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> @cnt <span style="color: gray">=</span> @cnt <span style="color: gray">+</span> 1<span style="color: gray">;</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">END</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Display Test Results &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: fuchsia">DATEDIFF</span><span style="color: gray">(</span>ms<span style="color: gray">,</span> @StartTime<span style="color: gray">,</span> <span style="color: fuchsia">GETDATE</span><span style="color: gray">())</span> <span style="color: blue">AS</span> Duration_ms</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: gray">,</span>@Results <span style="color: blue">AS</span> <span style="color: red">'Right Append 2'</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">GO</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ===&lt; TEST A: 2nd Run &gt;==============</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Set Test Specific Variables &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @CommSourceID <span style="color: blue">BIGINT</span><span style="color: gray">;</span> <span style="color: blue">SELECT</span> @CommSourceID <span style="color: gray">=</span> <span style="color: red">'1234567'</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: red; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Set Harness Variables &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @Results <span style="color: blue">VARCHAR</span><span style="color: gray">(</span>20<span style="color: gray">)</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @cnt <span style="color: blue">INT</span><span style="color: gray">;</span><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">SET</span> @cnt <span style="color: gray">=</span> 0</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @StartTime <span style="color: blue">DATETIME</span><span style="color: gray">;</span> <span style="color: blue">SET</span> @StartTime <span style="color: gray">=</span> <span style="color: fuchsia">GETDATE</span><span style="color: gray">()</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Execute Test many times &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHILE</span> @cnt <span style="color: gray">&lt;</span> $<span style="color: gray">(</span>LOOPCNT<span style="color: gray">)</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">BEGIN</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Insert your Test Query Below here &gt;---</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> @Results <span style="color: gray">=</span> <span style="color: fuchsia">SUBSTRING</span><span style="color: gray">(</span><span style="color: red">'0000000000'</span><span style="color: gray">,</span> 1<span style="color: gray">,</span> 10 <span style="color: gray">-</span> <span style="color: fuchsia">LEN</span><span style="color: gray">(</span><span style="color: fuchsia">CAST</span><span style="color: gray">(</span>@CommSourceID <span style="color: blue">AS</span> <span style="color: blue">varchar</span><span style="color: gray">(</span>10<span style="color: gray">))))</span> <span style="color: gray">+</span> <span style="color: fuchsia">CAST</span><span style="color: gray">(</span>@CommSourceID <span style="color: blue">AS</span> <span style="color: blue">varchar</span><span style="color: gray">(</span>10<span style="color: gray">))</span> </p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Insert your Test Query Above here &gt;---</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> @cnt <span style="color: gray">=</span> @cnt <span style="color: gray">+</span> 1<span style="color: gray">;</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">END</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Display Test Results &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: fuchsia">DATEDIFF</span><span style="color: gray">(</span>ms<span style="color: gray">,</span> @StartTime<span style="color: gray">,</span> <span style="color: fuchsia">GETDATE</span><span style="color: gray">())</span> <span style="color: blue">AS</span> Duration_ms</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: gray">,</span>@Results <span style="color: blue">AS</span> <span style="color: red">'Substring Manipulation 2'</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">GO</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ===&lt; Empty Test: Measure Test Harness overhead &gt;==============</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Set Test Specific Variables &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @CommSourceID <span style="color: blue">BIGINT</span><span style="color: gray">;</span> <span style="color: blue">SELECT</span> @CommSourceID <span style="color: gray">=</span> <span style="color: red">'1234567'</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: red; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Set Harness Variables &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @Results <span style="color: blue">VARCHAR</span><span style="color: gray">(</span>20<span style="color: gray">)</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @cnt <span style="color: blue">INT</span><span style="color: gray">;</span><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">SET</span> @cnt <span style="color: gray">=</span> 0</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @StartTime <span style="color: blue">DATETIME</span><span style="color: gray">;</span> <span style="color: blue">SET</span> @StartTime <span style="color: gray">=</span> <span style="color: fuchsia">GETDATE</span><span style="color: gray">()</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Execute Test many times &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHILE</span> @cnt <span style="color: gray">&lt;</span> $<span style="color: gray">(</span>LOOPCNT<span style="color: gray">)</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">BEGIN</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Insert your Test Query Below here &gt;---</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- &lt; do nothing here - empty test &gt;</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Insert your Test Query Above here &gt;---</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> @cnt <span style="color: gray">=</span> @cnt <span style="color: gray">+</span> 1<span style="color: gray">;</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">END</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Display Test Results &gt;---</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: fuchsia">DATEDIFF</span><span style="color: gray">(</span>ms<span style="color: gray">,</span> @StartTime<span style="color: gray">,</span> <span style="color: fuchsia">GETDATE</span><span style="color: gray">())</span> <span style="color: blue">AS</span> Duration_ms</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: gray">,</span>@Results <span style="color: blue">AS</span> <span style="color: red">'Empty Harness 2'</span> <span style="color: green">-- &lt;&lt; Meaningful label for test</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">GO</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ===&lt; END &gt;==============</p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt; font-weight: bold; text-decoration: underline">&#160;</p>  <h5><u><font size="3" face="Segoe UI">Example 2:<span style="mso-spacerun: yes">&#160; </span>Can trivial User Defined Functions slow you down.</font></u></h5>  <p style="margin: 0in; font-family: calibri; font-size: 11pt">This code sample has been truncated to save space it only shows tests running once. </p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt">It compares a User Defined Function,vs the UDF rewritten, vs the rewrite just executed in the query without calling a UDF vs the inline code trimmed to its essentials. While the rewritten UDF code was much faster, calling it as a UDF made the difference negligible. By removing the calling overhead &amp; incorporating it into the TSQL Query that was calling the UDF you start to see real perf gains. Eg ~50 times faster.</p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt"><span style="font-weight: bold">Note 1:</span><span style="mso-spacerun: yes">&#160; </span>It is wrong to draw a conclusion from these results that all User Functions are bad &amp; hurt performance. I have seen many occasions where they result in a perf gain. However, they are nearly always slower than putting the same code in-line or taking a huge join out of a UDF &amp; extending the joins in your base table to include these extra table.<span style="mso-spacerun: yes">&#160; </span>Ie: It is more efficient to join an extra table to your base query. </p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt">NB: An exception to this, is if the UDF permits you to return 1 row based on a parameter, this becomes like a bookmark lookup &amp; can be much more efficient than joining with a huge table.</p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt"><span style="font-weight: bold">Note 2:</span> I agree it would be easier to use the SQL 2008 Time data type, this code was written long ago &amp; needed to run on SQL 2000 &amp; SQL 2005 systems. </p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt"><span style="font-weight: bold">Note 3:</span> As we iterate thru the loop it is also passing all possible values as parameter to the User Function. Just in case one code path is slower than another. </p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt; text-decoration: underline">Original User Function</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- =============================================</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- Author:<span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>Some Noddy</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- Create date: 5 June 2005</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- Description:<span style="mso-spacerun: yes">&#160;&#160;&#160;&#160; </span>This converts a number of Minutes into a Time string without a date.</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- =============================================</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">USE</span> TempDB</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">go</span> </p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">CREATE</span> <span style="color: blue">FUNCTION</span> [dbo]<span style="color: gray">.</span>[uf_MinutestoStringTime]<span style="color: blue"> </span><span style="color: gray">(</span>@minutes <span style="color: blue">int</span><span style="color: gray">)</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">RETURNS</span> <span style="color: blue">varchar</span><span style="color: gray">(</span>8<span style="color: gray">)</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">AS</span> <span style="color: blue">BEGIN</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @RETURN <span style="color: blue">varchar</span><span style="color: gray">(</span>8<span style="color: gray">),</span></p>  <p style="margin: 0in 0in 0in 1.125in; font-family: &#39;Courier New&#39;; font-size: 10pt">@computedminutes <span style="color: blue">int</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">IF</span> @minutes <span style="color: gray">IS</span> <span style="color: gray">NULL</span></p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">RETURN</span> <span style="color: red">''</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">IF</span> @minutes <span style="color: gray">&gt;</span> 1440 </p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">RETURN</span> <span style="color: red">''</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">IF</span> @minutes <span style="color: gray">&lt;</span> 1</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">RETURN</span> <span style="color: red">''</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: red; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">IF</span> @minutes <span style="color: gray">=</span> 720</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> @RETURN <span style="color: gray">=</span> <span style="color: red">'12:00 PM'</span> </p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">IF</span> @minutes <span style="color: gray">=</span> 1440</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> @RETURN <span style="color: gray">=</span> <span style="color: red">'12:00 AM'</span> </p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">ELSE</span> <span style="color: blue">IF</span> @minutes <span style="color: gray">&lt;</span> 780</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> @RETURN <span style="color: gray">=</span> <span style="color: fuchsia">CAST</span><span style="color: gray">(</span><span style="color: fuchsia">ABS</span><span style="color: gray">(</span>@minutes <span style="color: gray">/</span> 60<span style="color: gray">)</span> <span style="color: blue">AS</span> <span style="color: blue">VARCHAR</span><span style="color: gray">(</span>3<span style="color: gray">))+</span><span style="color: red">':'</span><span style="color: gray">+</span> <span style="color: gray">right(</span><span style="color: red">'0'</span> </p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: gray">+</span> <span style="color: fuchsia">CAST</span><span style="color: gray">(</span>@minutes <span style="color: gray">-</span><span style="color: blue"> </span><span style="color: gray">(</span> <span style="color: fuchsia">ABS</span><span style="color: gray">(</span>@minutes <span style="color: gray">/</span> 60<span style="color: gray">)</span> <span style="color: gray">*</span> 60<span style="color: gray">)</span> <span style="color: blue">AS</span> <span style="color: blue">VARCHAR</span><span style="color: gray">(</span>4<span style="color: gray">)),</span>2<span style="color: gray">)</span> <span style="color: gray">+</span> <span style="color: red">' AM'</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">ELSE</span> <span style="color: blue">IF</span> @minutes <span style="color: gray">&gt;</span> 780</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">BEGIN</span><span style="mso-spacerun: yes">&#160;&#160;&#160; </span></p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> @computedminutes <span style="color: gray">=</span> @minutes <span style="color: gray">-</span> 720<span style="mso-spacerun: yes">&#160;&#160;&#160; </span></p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> @RETURN <span style="color: gray">=</span> <span style="color: fuchsia">cast</span><span style="color: gray">(</span><span style="color: fuchsia">abs</span><span style="color: gray">(</span>@computedminutes <span style="color: gray">/</span> 60<span style="color: gray">)</span> <span style="color: blue">AS</span> <span style="color: blue">VARCHAR</span><span style="color: gray">(</span>3<span style="color: gray">))+</span><span style="color: red">':'</span><span style="color: gray">+</span> <span style="color: gray">right(</span><span style="color: red">'0'</span> </p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: gray">+</span> <span style="color: fuchsia">CAST</span><span style="color: gray">(</span>@computedminutes <span style="color: gray">-</span><span style="color: blue"> </span><span style="color: gray">(</span> <span style="color: fuchsia">ABS</span><span style="color: gray">(</span>@computedminutes <span style="color: gray">/</span> 60<span style="color: gray">)</span> <span style="color: gray">*</span> 60<span style="color: gray">)</span> <span style="color: blue">AS</span> <span style="color: blue">VARCHAR</span><span style="color: gray">(</span>4<span style="color: gray">)),</span>2<span style="color: gray">)</span> </p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: gray">+</span> <span style="color: blue">CASE</span> <span style="color: blue">WHEN</span> @minutes <span style="color: gray">&gt;</span> 719 <span style="color: blue">THEN</span> <span style="color: red">' PM'</span> </p>  <p style="margin: 0in 0in 0in 1.125in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHEN</span> @minutes <span style="color: gray">&lt;</span> 719 <span style="color: blue">THEN</span> <span style="color: red">' AM'</span> </p>  <p style="margin: 0in 0in 0in 1.125in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">ELSE</span> <span style="color: red">''</span> </p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">END</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">END</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">RETURN</span> @RETURN</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">END</p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt; text-decoration: underline"><font color="#333333" size="3"><strong>Refactored User Function</strong></font></p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- =============================================</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- Author:<span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>David LEAN</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- Create date: 25 Sept 2009</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- Description:<span style="mso-spacerun: yes">&#160;&#160;&#160; </span>This converts a number of Minutes into a Time string without a date. </p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- Note:<span style="mso-spacerun: yes">&#160;&#160;&#160; </span>It is an error to pass more minutes than contained in a single day. ie: 1400</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">--<span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>It is an error to pass a negative value.</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- 0 = 12:00 AM, 59 = 12:59 AM</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- 719 = 11:59 AM, 720 = 12:00 PM</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- 1440 = 12:00 AM</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- =============================================</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">USE</span> TempDB</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">GO</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">CREATE</span> <span style="color: blue">FUNCTION</span> [dbo]<span style="color: gray">.</span>[uf_MinutestoStringTime2]<span style="color: blue"> </span><span style="color: gray">(</span> @minutes <span style="color: blue">int</span> <span style="color: gray">)</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">RETURNS</span> <span style="color: blue">varchar</span><span style="color: gray">(</span>8<span style="color: gray">)</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">AS</span> <span style="color: blue">BEGIN</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">IF<span style="mso-spacerun: yes">&#160;&#160;&#160;&#160; </span></span><span style="color: gray">(</span>@minutes <span style="color: gray">&gt;=</span> 1<span style="color: gray">)</span> <span style="color: gray">AND</span><span style="color: blue"> </span><span style="color: gray">(</span>@minutes <span style="color: gray">&lt;=</span> 1440<span style="color: gray">)</span></p>  <p style="margin: 0in 0in 0in 0.75in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">RETURN</span> <span style="color: fuchsia">ISNULL</span><span style="color: gray">(</span><span style="color: fuchsia">LTRIM</span><span style="color: gray">(</span><span style="color: fuchsia">STUFF</span><span style="color: gray">(RIGHT(</span> <span style="color: fuchsia">CONVERT</span><span style="color: gray">(</span> <span style="color: blue">VARCHAR</span><span style="color: gray">(</span>20<span style="color: gray">),</span> <span style="color: fuchsia">DATEADD</span><span style="color: gray">(</span>mi<span style="color: gray">,</span> @minutes<span style="color: gray">,</span> <span style="color: red">'12:00 AM'</span><span style="color: gray">))</span> <span style="color: gray">,</span>7 <span style="color: gray">),</span> 6<span style="color: gray">,</span>0<span style="color: gray">,</span> <span style="color: red">' '</span><span style="color: gray">)),</span> <span style="color: red">''</span><span style="color: gray">)</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">RETURN</span> <span style="color: red">''</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">END</p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt">Sample Test Harness to compare both User Functions and Putting the code inline. </p>  <p style="margin: 0in; font-family: calibri; font-size: 11pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ==============================================</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- Test Harness to compare impact of small High Frequency Operations: eg: Things called once for each row in a query.</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- Method: Remember to subtract the overhead of the MAXLOOPS from each result.</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">--<span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>Remember to Click Menu: Query-&gt;SQLCMD mode to allow the MaxMAXLOOPS Counter.</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">USE</span> TempDB</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> <span style="color: blue">NOCOUNT</span> <span style="color: blue">ON</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- Change this value to impact ALL tests</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="background: silver; mso-highlight: silver">:SETVAR MAXLOOPS 200000</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="background: silver; mso-highlight: silver"></span>&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- =========================================================================================</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Pre-Test: Calculate Overhead of Looping code &gt;---</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @cntLoop <span style="color: blue">INT</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> @cntLoop <span style="color: gray">=</span> 1</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @Minutes <span style="color: blue">INT</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @Result <span style="color: blue">VARCHAR</span><span style="color: gray">(</span>8<span style="color: gray">);</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @StartTime <span style="color: blue">DATETIME</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> @StartTime <span style="color: gray">=</span> <span style="color: fuchsia">GETDATE</span><span style="color: gray">()</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHILE</span> @cntLoop <span style="color: gray">&lt;</span> $<span style="color: gray">(</span>MAXLOOPS<span style="color: gray">)</span> <span style="color: blue">BEGIN</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> @Minutes <span style="color: gray">=</span> @cntLoop <span style="color: gray">%</span> 1441</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> @Result <span style="color: gray">=</span> 1 <span style="color: green">-- Empty assignment </span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> @cntLoop <span style="color: gray">=</span> @cntLoop <span style="color: gray">+</span> 1</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">END</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: fuchsia">DATEDIFF</span><span style="color: gray">(</span>ms<span style="color: gray">,</span> @StartTime<span style="color: gray">,</span> <span style="color: fuchsia">GETDATE</span><span style="color: gray">()</span> <span style="color: gray">)</span> <span style="color: blue">AS</span> <span style="color: red">'Empty MAXLOOPS Overhead'</span><span style="color: gray">;</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">go</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- =========================================================================================</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Test 1: Calculate Overhead of Calling existing User Function &gt;---</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @cntLoop <span style="color: blue">INT</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> @cntLoop <span style="color: gray">=</span> 1</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @Minutes <span style="color: blue">INT</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @Result <span style="color: blue">VARCHAR</span><span style="color: gray">(</span>8<span style="color: gray">);</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @StartTime <span style="color: blue">DATETIME</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> @StartTime <span style="color: gray">=</span> <span style="color: fuchsia">GETDATE</span><span style="color: gray">()</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHILE</span> @cntLoop <span style="color: gray">&lt;</span> $<span style="color: gray">(</span>MAXLOOPS<span style="color: gray">)</span> <span style="color: blue">BEGIN</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> @Minutes <span style="color: gray">=</span> @cntLoop <span style="color: gray">%</span> 1441 <span style="color: green">-- Ensure you test every possible value. </span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> @Result <span style="color: gray">=</span> [dbo]<span style="color: gray">.</span>[uf_MinutestoStringTime]<span style="color: blue"> </span><span style="color: gray">(</span>@cntLoop<span style="color: gray">)</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> @cntLoop <span style="color: gray">=</span> @cntLoop <span style="color: gray">+</span> 1</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">END</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: fuchsia">DATEDIFF</span><span style="color: gray">(</span>ms<span style="color: gray">,</span> @StartTime<span style="color: gray">,</span> <span style="color: fuchsia">GETDATE</span><span style="color: gray">()</span> <span style="color: gray">)</span> <span style="color: blue">AS</span> <span style="color: red">'uf_MinutestoStringTime'</span><span style="color: gray">;</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">go</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- =========================================================================================</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Test 2: Calculate Overhead of equivalent TSQL Statment &gt;---</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- NB: This returns slightly different results as I believe the existing code gives wrong results between 12:00AM -1:00am &amp; also 12:00pm &amp; 1-pm</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- My results show this takes ~4% of Original ie: 25 Times faster.</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @cntLoop <span style="color: blue">INT</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> @cntLoop <span style="color: gray">=</span> 1</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @Minutes <span style="color: blue">INT</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @Result <span style="color: blue">VARCHAR</span><span style="color: gray">(</span>8<span style="color: gray">);</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @StartTime <span style="color: blue">DATETIME</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> @StartTime <span style="color: gray">=</span> <span style="color: fuchsia">GETDATE</span><span style="color: gray">()</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHILE</span> @cntLoop <span style="color: gray">&lt;</span> $<span style="color: gray">(</span>MAXLOOPS<span style="color: gray">)</span> <span style="color: blue">BEGIN</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> @Minutes <span style="color: gray">=</span> @cntLoop <span style="color: gray">%</span> 1441</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> @Result <span style="color: gray">=</span> <span style="color: fuchsia">LTRIM</span><span style="color: gray">(</span><span style="color: fuchsia">STUFF</span><span style="color: gray">(RIGHT(</span> <span style="color: fuchsia">CONVERT</span><span style="color: gray">(</span> <span style="color: blue">VARCHAR</span><span style="color: gray">(</span>20<span style="color: gray">),</span> <span style="color: fuchsia">DATEADD</span><span style="color: gray">(</span>mi<span style="color: gray">,</span> @cntLoop<span style="color: gray">,</span> <span style="color: red">'12:00 AM'</span><span style="color: gray">))</span> <span style="color: gray">,</span> 7 <span style="color: gray">)</span> <span style="color: gray">,</span> 6<span style="color: gray">,</span>0<span style="color: gray">,</span> <span style="color: red">' '</span><span style="color: gray">))</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> @cntLoop <span style="color: gray">=</span> @cntLoop <span style="color: gray">+</span> 1</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">END</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: fuchsia">DATEDIFF</span><span style="color: gray">(</span>ms<span style="color: gray">,</span> @StartTime<span style="color: gray">,</span> <span style="color: fuchsia">GETDATE</span><span style="color: gray">()</span> <span style="color: gray">)</span> <span style="color: blue">AS</span> <span style="color: red">'Ltrim Inline'</span><span style="color: gray">;</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">go</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- =========================================================================================</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Test 3: Calculate Overhead of equivalent TSQL Statment BUT no space between Time &amp; AM/PM &gt;---</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- NB: This returns slightly different results as I believe the existing code gives wrong results between 12:00AM -1:00am &amp; also 12:00pm &amp; 1-pm</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- My results show this takes ~2% of Original ie: 50 Times faster.</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @cntLoop <span style="color: blue">INT</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> @cntLoop <span style="color: gray">=</span> 1</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @Minutes <span style="color: blue">INT</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @Result <span style="color: blue">VARCHAR</span><span style="color: gray">(</span>8<span style="color: gray">);</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @StartTime <span style="color: blue">DATETIME</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> @StartTime <span style="color: gray">=</span> <span style="color: fuchsia">GETDATE</span><span style="color: gray">()</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHILE</span> @cntLoop <span style="color: gray">&lt;</span> $<span style="color: gray">(</span>MAXLOOPS<span style="color: gray">)</span> <span style="color: blue">BEGIN</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> @Minutes <span style="color: gray">=</span> @cntLoop <span style="color: gray">%</span> 1441</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> @Result <span style="color: gray">=</span><span style="color: blue"> </span><span style="color: gray">(RIGHT(</span> <span style="color: fuchsia">CONVERT</span><span style="color: gray">(</span> <span style="color: blue">VARCHAR</span><span style="color: gray">(</span>20<span style="color: gray">),</span> <span style="color: fuchsia">DATEADD</span><span style="color: gray">(</span>mi<span style="color: gray">,</span> @cntLoop<span style="color: gray">,</span> <span style="color: red">'12:00 AM'</span><span style="color: gray">))</span> <span style="color: gray">,</span> 7 <span style="color: gray">)</span> <span style="color: gray">)</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> @cntLoop <span style="color: gray">=</span> @cntLoop <span style="color: gray">+</span> 1</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">END</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: fuchsia">DATEDIFF</span><span style="color: gray">(</span>ms<span style="color: gray">,</span> @StartTime<span style="color: gray">,</span> <span style="color: fuchsia">GETDATE</span><span style="color: gray">()</span> <span style="color: gray">)</span> <span style="color: blue">AS</span> <span style="color: red">'uf inline'</span><span style="color: gray">;</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">go</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- =========================================================================================</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- ---&lt; Test 4: Calculate Overhead of equivalent TSQL Statment put into a User Function &gt;---</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- NB: This returns slightly different results as I believe the existing code gives wrong results between 12:00AM -1:00am &amp; also 12:00pm &amp; 1-pm</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- My results show this takes ~98.5% of Original ie: Calling overhead on trivial User Functions can have a huge Performance Impact.</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @cntLoop <span style="color: blue">INT</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> @cntLoop <span style="color: gray">=</span> 1</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @Minutes <span style="color: blue">INT</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @Result <span style="color: blue">VARCHAR</span><span style="color: gray">(</span>8<span style="color: gray">);</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">DECLARE</span> @StartTime <span style="color: blue">DATETIME</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> @StartTime <span style="color: gray">=</span> <span style="color: fuchsia">GETDATE</span><span style="color: gray">()</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">WHILE</span> @cntLoop <span style="color: gray">&lt;</span> $<span style="color: gray">(</span>MAXLOOPS<span style="color: gray">)</span> <span style="color: blue">BEGIN</span></p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> @Minutes <span style="color: gray">=</span> @cntLoop <span style="color: gray">%</span> 1441</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> @Result <span style="color: gray">=</span> [dbo]<span style="color: gray">.</span>uf_MinutestoStringTime2<span style="color: blue"> </span><span style="color: gray">(</span>@cntLoop<span style="color: gray">)</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: gray; font-size: 10pt">&#160;</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SET</span> @cntLoop <span style="color: gray">=</span> @cntLoop <span style="color: gray">+</span> 1</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">END</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; font-size: 10pt"><span style="color: blue">SELECT</span> <span style="color: fuchsia">DATEDIFF</span><span style="color: gray">(</span>ms<span style="color: gray">,</span> @StartTime<span style="color: gray">,</span> <span style="color: fuchsia">GETDATE</span><span style="color: gray">()</span> <span style="color: gray">)</span> <span style="color: blue">AS</span> <span style="color: red">'uf_MinutestoStringTime2'</span><span style="color: gray">;</span></p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: blue; font-size: 10pt">go</p>  <p style="margin: 0in; font-family: &#39;Courier New&#39;; color: green; font-size: 10pt">-- =========================================================================================</p>  <p style="margin: 0in 0in 0in 0.75in; font-family: calibri; color: #333333; font-size: 11pt">&#160;</p>  <p style="margin: 0in; font-family: &#39;Segoe UI&#39;; color: blue; font-size: 12pt; font-weight: bold; text-decoration: underline">Warnings</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; color: #333333; font-size: 11pt">This approach has its limitations. It tends to be less useful for comparing if a query works better with or without an index. In that case you really need either :-</p>  <ol style="margin-top: 0in; unicode-bidi: embed; font-family: calibri; direction: ltr; margin-bottom: 0in; margin-left: 0.75in; font-size: 11pt" type="1">   <li style="margin-top: 0px; margin-bottom: 0px; color: #333333; vertical-align: middle" value="value"><span style="font-family: calibri; font-size: 11pt">Run the same query against 2 databases, one with the indexes &amp; the other without. OR</span> </li>    <li style="margin-top: 0px; margin-bottom: 0px; color: #333333; vertical-align: middle" value="value"><span style="font-family: calibri; font-size: 11pt">Run the test, create the index &amp; run the other test. OR</span> </li>    <li style="margin-top: 0px; margin-bottom: 0px; color: #333333; vertical-align: middle" value="value"><span style="font-family: calibri; font-size: 11pt"><span style="mso-spacerun: yes">&#160;</span>Use Visual Studio for DB Professionals &amp;/or RML Utilities to create &amp; measure the load.         <br />Fortunately using SET STATISTIC IO ON means you should be able to quickly see the winner without resorting to this timing loop approach.         <br />&#160;</span> </li> </ol>  <p style="margin: 0in; font-size: 11pt"><span style="font-family: &#39;Segoe UI&#39;; color: blue; font-weight: bold; text-decoration: underline">Final Thought</span><span style="font-family: calibri; color: #3a3e43">      <br /></span><span style="font-family: calibri; color: #333333">So next time you wonder which is faster :-</span></p>  <ol>   <li style="margin-top: 0px; margin-bottom: 0px; color: #333333; vertical-align: middle" value="value"><span style="font-family: calibri; font-size: 11pt"><font color="#ff00ff"><font color="#ff00ff">           <p><font size="2" face="Courier New">GETDATE</font></p>         </font><font color="#808080"><font color="#808080"><font size="2" face="Courier New">()</font></font></font><font size="2" face="Courier New"> <font size="2"><font size="2"><strong>or</strong></font></font> </font><font color="#ff00ff"><font color="#ff00ff" size="2" face="Courier New">CURRENT_TIMESTAMP</font></font></font></span> </li>    <li style="margin-top: 0px; margin-bottom: 0px; color: #333333; vertical-align: middle"><font size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">“ <font face="Courier New">IF</font></font></font><font face="Courier New"><font size="2"> </font><font color="#ff00ff" size="2"><font color="#ff00ff" size="2">OBJECT_ID</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font color="#ff0000" size="2"><font color="#ff0000" size="2">N'dbo.MyTable'</font></font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">N'U'</font></font><font color="#808080" size="2"><font color="#808080" size="2">)</font></font><font size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">IS</font></font><font size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">NOT</font></font><font size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">NULL;</font></font></font><font face="Segoe UI"><font color="#000000"><strong><font size="2"> “ </font><font size="2"><font size="2">or</font></font><font size="2">                <br /></font></strong></font></font><font color="#0000ff" size="2"><font color="#0000ff" size="2">“ <font face="Courier New">IF</font></font></font><font face="Courier New"><font size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">NOT</font></font><font size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">EXISTS</font></font><font color="#0000ff" size="2"><font color="#0000ff" size="2"> </font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font color="#0000ff" size="2"><font color="#0000ff" size="2">SELECT</font></font><font size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">*</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">FROM</font></font><font size="2"> </font><font color="#008000" size="2"><font color="#008000" size="2">sys</font></font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font color="#008000" size="2"><font color="#008000" size="2">objects</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">where</font></font><font size="2"> </font><font color="#ff00ff" size="2"><font color="#ff00ff" size="2">object_id</font></font><font size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font size="2"> </font><font color="#ff00ff" size="2"><font color="#ff00ff" size="2">OBJECT_ID</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font color="#ff0000" size="2"><font color="#ff0000" size="2">N'dbo.MyTable'</font></font><font color="#808080" size="2"><font color="#808080" size="2">)</font></font><font size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">AND</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">Type</font></font><font size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">N'U'</font></font><font color="#808080" size="2"><font color="#808080" size="2">);</font></font></font></font>       <p><font size="2"></font></p>   </li>    <li>     <div style="margin-top: 0px; margin-bottom: 0px; color: #333333; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">Is there much overhead in putting this code in a USER DEFINED FUNCTION &amp; calling it? </span></div>   </li>    <li>     <div style="margin-top: 0px; margin-bottom: 0px; color: #333333; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">Is it better to check if a variable is NULL before needlessly passing it to a function? ie:          <br /><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font face="Courier New">IF </font></font><font face="Courier New"><font size="2">@productName </font><font color="#808080" size="2"><font color="#808080" size="2">IS</font></font><font size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">NOT</font></font><font size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">NULL</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">BEGIN                  <br /></font></font></font><font face="Courier New"><font color="#0000ff" size="2"><font color="#0000ff" size="2">&#160;&#160;&#160;&#160; SET</font></font><font size="2"> @productName </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font size="2"> </font><font color="#ff00ff" size="2"><font color="#ff00ff" size="2">LTRIM</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font size="2">@productName</font><font color="#808080" size="2"><font color="#808080" size="2">)</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">SET</font></font><font size="2"> @productName </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font size="2"> </font><font color="#ff00ff" size="2"><font color="#ff00ff" size="2">RTRIM</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font size="2">@productName</font><font color="#808080" size="2"><font color="#808080" size="2">)</font></font><font size="2">                <br /></font></font><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font face="Courier New">END                 <br /></font></font></font><font color="#333333" size="3" face="Segoe UI"><strong>vs                <br /></strong></font></font><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font face="Courier New">SET </font></font><font face="Courier New"><font size="2">@productName </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font size="2"> </font><font color="#ff00ff" size="2"><font color="#ff00ff" size="2">LTRIM</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font size="2"> </font><font color="#ff00ff" size="2"><font color="#ff00ff" size="2">RTRIM</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font size="2">@productName</font><font color="#808080" size="2"><font color="#808080" size="2">)</font></font><font size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">)</font></font><font size="2"> </font></font></font></span></div>   </li> </ol>  <p style="margin-top: 0px; margin-bottom: 0px; color: #333333; vertical-align: middle"><span style="font-family: calibri; font-size: 11pt">Now you can quickly recycle this code from here &amp; test it out.      <br />(By the way the answers are; No Difference, 1st Option 60% faster, tiny udfs can be 50 times slower than inline., Later alternative is 2.5x faster)&#160; <br />&#160; <br /></span></p>  <p style="margin: 0in; font-family: &#39;Segoe UI&#39;; color: blue; font-size: 12pt; font-weight: bold; text-decoration: underline">Random Thought for the Post. </p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt">In meetings I often hear people say &quot;There's no such thing as a stupid question&quot;.</p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt">That might be true, however I think &quot;Excuse me Mr Customs man, do you think the heroin in my padded bra makes my breasts look unnaturally large?&quot; must come close. … Especially if you are a man. </p>  <p style="margin: 0in 0in 0in 0.375in; font-family: calibri; font-size: 11pt">&#160;</p>  <p><font size="2" face="Arial"><strong>I hope you find this useful. As always I’m very interested in your comments, Good or bad. thx Dave</strong></font></p>]]></content:encoded>
    </item>
    <item>
      <title>Solution: Can edit, but can’t process, an Analysis Server Cube using ORACLE data</title>
      <link>https://docs.microsoft.com/archive/blogs/davidlean/solution-can-edit-but-cant-process-an-analysis-server-cube-using-oracle-data</link>
      <pubDate>Sat, 16 Oct 2010 00:34:26 GMT</pubDate>
      <dc:creator><![CDATA[davele]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/davidlean/2010/10/16/solution-can-edit-but-cant-process-an-analysis-server-cube-using-oracle-data/</guid>
      <description><![CDATA[&#160;  Recently I was developing a SQL Server Analysis Server cube using Oracle as a data source....]]></description>
      <content:encoded><![CDATA[<p>&#160;</p>  <p>Recently I was developing a SQL Server Analysis Server cube using Oracle as a data source. Weirdly the the development environment (BI Dev Studio) could see the Oracle schema &amp; let me explore the data. But when I tried to process the cube or one of its dimensions, it died indicating that I couldn’t connect to the Oracle Server. Which clearly I could do as I’d been building &amp; running SQL Reports from the same project &amp; could see the data in the development tool.</p>  <p>If you are experiencing any of the following errors this post may help.</p>  <ul>   <li><strong><font color="#ff0000" size="2">Bad Username / Bad Password</font></strong> </li>    <li><strong><font color="#ff0000" size="2">ORA-01017: Invalid username/password; logon denied.</font></strong> </li>    <li><strong><font color="#ff0000" size="2">ORA-12154: TNS could not resolve the connect identifier specified.</font> </strong></li> </ul>  <p>While trying to resolve this issue I read a whole lot of misleading information on Internet forums. These misguided “solutions” distracted me. I hope this post will make it easier for you. </p>  <h2>In Short:</h2>  <blockquote>   <p><strong>You develop the cube</strong> in the Business Intelligence Development Studio (BIDS) tool. It is 32 bit process that connects to both Analysis Server &amp; your Oracle Data source. <em>(Purple arrow)</em> It uses the connection information you defined in the Data Source object you added to the Project.</p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/8372.image_2.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/8372.image_5F00_2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="BIDS connects with Your User Credentials to Oracle &amp; SSAS" border="0" alt="BIDS connects with Your User Credentials to Oracle &amp; SSAS" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/6708.image_thumb.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/6708.image_5F00_thumb.png" width="644" height="221" /></a>       <br /></p>    <p><strong>When you process the cube or a Dimension</strong>, BIDS passes the relevant definitions to SQL Server Analysis Server (SSAS). <em>(Purple arrow)</em> The SSAS attempts to connect to the Oracle database to process the data. <em>(Blue Arrow)       <br /></em>&#160;<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/7317.image_4.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/7317.image_5F00_4.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="SSAS connects to Oracle with the credentials of its Service Account" border="0" alt="SSAS connects to Oracle with the credentials of its Service Account" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/6330.image_thumb_1.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/6330.image_5F00_thumb_5F00_1.png" width="644" height="219" /></a> </p>    <p>It makes no difference if BIDS is running on the same machine as SSAS. It is designed to work in any of the topologies shown above. That way if SSAS is on a dedicated Server it can run with the full power of a server. That means SSAS doesn’t use the same credentials as the BIDS process. </p>    <p>SSAS does use the same information in the data source to connect to Oracle as you are using from BIDS but runs them under the credentials of the Windows Account used to start the service. Commonly the Service is started as either “NT AUTHORITY\NetworkService”, &quot;Local System” or “Local Service”. It is highly likely that this account will not have sufficient permission to connect thru your domain to the Oracle Server. Especially in a heterogeneous environment of Linx / Unix / Windows, with a variety of Authentication systems etc.</p>    <p>It is possible that the Account you are using to run SSAS doesn’t have permission to read the Oracle directories containing the TNSNAMES.ORA file(s) which the Oracle Client interface needs to connect to your Oracle database. (test this by temporarily putting the SSAS Account into the local Administrators group)</p>    <p>It is possible that you have the wrong “Bitness” Oracle drivers installed. BIDS is a 32 bit application, on 64 bit windows it will be running in a 32 bit shell. But your SSAS system may be full 64 bit. You may need both 32 bit &amp; 64 bit Oracle drivers installed &amp; configured. (test this by installing a 64 bit Oracle client &amp; seeing that it works correctly)</p> </blockquote>  <p>&#160;</p>  <h3>Trouble shooting technique.&#160; </h3>  <blockquote>   <p><strong><u>Test 1:</u> If you are running BIDS &amp; SSAS on the same machine <u>and</u> BIDS is connecting to Oracle OK.</strong> </p>    <ul>     <li>Try changing the SSAS Service Logon account to the account you used to logon to Windows. (see steps below). If it lets you process the cube, problem solved. </li>      <li>Now go create a dedicated account on the Windows Domain for your OLAP service &amp; use it. (otherwise when you change your password, OLAP server will not start, as you will likely forget to change it at the same time.&#160; :-) ).&#160; </li>   </ul>    <p><strong><u>Test 2:</u> If SSAS is on a different machine.</strong> </p>    <ul>     <li>As above, check the Service Account, &amp; possibly change it to an account you know can connect over the network to Oracle. </li>      <li>Also check that you can connect from that server to Oracle. The easiest way is to install an Oracle client tool, eg: Oracle Enterprise Manager, TOAD for Oracle, or similar. </li>      <li></li>   </ul> </blockquote>  <h3>Bum steer</h3>  <blockquote>   <p>While trawling thru the net, looking for Oracle insight I stumbled on this post. It seemed insightful. It proved to be total garbage. Analysis Service does not make connections by doing something funky with HOME0. You do not need to edit registries or change Oracle connection information an a special way for SSAS. If an Oracle app of the same bitness (32/64 bit) can connect, then SSAS should be able to too.</p>    <p><a href="https://www.tek-tips.com/viewthread.cfm?qid=1016413&amp;page=28">https://www.tek-tips.com/viewthread.cfm?qid=1016413&amp;page=28</a>       <br /><em>”In its wisdom, Analysis Services uses the Oracle &quot;HOME&quot; string in the registry to find the TNSNAMES.ora.        <br />When you're building the cube and the dimensions, it finds TNSNAMES.ora ok using HOME1, but then when you want to run the cube, it decides to use HOME0 as the Oracle Home directory - and I didn't have TNSNAMES.ora. Why can't Microsoft write the software to use a standard Oracle Home location? “</em></p> </blockquote>  <h2>Details</h2>  <p>As some people are shaky on Windows &amp; mention they like pictures. Here are some screenshots that my help you. </p>  <h4>Step 1: Analysis Services cube processing failed.</h4>  <blockquote>   <p>When Processing Dimensions you get an error message indicating <strong><font color="#ff0000">the connection couldn’t be made to with the DataSource</font></strong>. You can ignore the rest of the errors as they are caused by this failure. </p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/3681.ORA-01017%20invalid%20username%20password%20logon%20denied_2.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/3681.ORA_2D00_01017-invalid-username-password-logon-denied_5F00_2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ORA-01017 invalid username password logon denied" border="0" alt="ORA-01017 invalid username password logon denied" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/8802.ORA-01017%20invalid%20username%20password%20logon%20denied_thumb.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/8802.ORA_2D00_01017-invalid-username-password-logon-denied_5F00_thumb.png" width="644" height="309" /></a>       <br /><font size="2"><font color="#000000">Picture: ORA-01017: Invalid username/password; logon denied. </font></font></p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/6266.ORA-12154%20%20TNS%20could%20not%20resolve%20the%20connect%20identifier%20specified._2.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/6266.ORA_2D00_12154--TNS-could-not-resolve-the-connect-identifier-specified._5F00_2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ORA-12154  TNS could not resolve the connect identifier specified." border="0" alt="ORA-12154  TNS could not resolve the connect identifier specified." src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/8726.ORA-12154%20%20TNS%20could%20not%20resolve%20the%20connect%20identifier%20specified._thumb.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/8726.ORA_2D00_12154--TNS-could-not-resolve-the-connect-identifier-specified._5F00_thumb.png" width="644" height="316" /></a>&#160; <br /><font color="#000000" size="2">Picture: ORA-12154: TNS could not resolve the connect identifier specified. </font></p>    <p><strong>Note:</strong> It is likely you received this message after you attempted to process a cube or dimension. As below.</p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/2860.Process%20Dimension_2.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/2860.Process-Dimension_5F00_2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Process Dimension" border="0" alt="Process Dimension" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/4213.Process%20Dimension_thumb.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/4213.Process-Dimension_5F00_thumb.png" width="244" height="125" /></a> </p>    <p>Right Click on the cube or Dimension you want to process.</p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/2475.Process%20Dimension%202_2.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/2475.Process-Dimension-2_5F00_2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Process Dimension 2" border="0" alt="Process Dimension 2" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/3630.Process%20Dimension%202_thumb.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/3630.Process-Dimension-2_5F00_thumb.png" width="210" height="244" /></a> </p>    <p>Click Run to begin the processing operation. </p> </blockquote>  <h4>&#160;</h4>  <h4>Step 2: Ensure the Windows Domain Account you are using is in the appropriate SSAS Admin group</h4>  <blockquote>   <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/1401.Add%20Domain%20Service%20Account%20to%20Group%20in%20Computer%20Management_2.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/1401.Add-Domain-Service-Account-to-Group-in-Computer-Management_5F00_2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Add Domain Service Account to Group in Computer Management" border="0" alt="Add Domain Service Account to Group in Computer Management" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/7380.Add%20Domain%20Service%20Account%20to%20Group%20in%20Computer%20Management_thumb.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/7380.Add-Domain-Service-Account-to-Group-in-Computer-Management_5F00_thumb.png" width="644" height="189" /></a> </p>    <ul>     <li>To Open Computer Management: Click Windows Start. </li>      <li>R.Click Computer –&gt; Manage. Expand the Local Users &amp; Groups node. </li>      <li>Search the Descriptions looking for Instances that say “Analysis Services” if you have more than one, make sure you change the one you are using :-) </li>      <li>Click “Add to Group…” </li>   </ul>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/4075.Computer%20Mgmnt%20Add%20to%20OLAP%20Group_2.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/4075.Computer-Mgmnt-Add-to-OLAP-Group_5F00_2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Computer Mgmnt Add to OLAP Group" border="0" alt="Computer Mgmnt Add to OLAP Group" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/0250.Computer%20Mgmnt%20Add%20to%20OLAP%20Group_thumb.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/0250.Computer-Mgmnt-Add-to-OLAP-Group_5F00_thumb.png" width="217" height="244" /></a> </p>    <ul>     <li>Click “Add” to add a new user to this group.        <br />In this case I’m adding a service account “MyOLAPServiceAccount”. </li>      <li>Then click “Check Names” &amp; if it finds it, click OK. </li>   </ul>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/4062.Add%20Domain%20Service%20Account%20to%20Group_2.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/4062.Add-Domain-Service-Account-to-Group_5F00_2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Add Domain Service Account to Group" border="0" alt="Add Domain Service Account to Group" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/2402.Add%20Domain%20Service%20Account%20to%20Group_thumb.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/2402.Add-Domain-Service-Account-to-Group_5F00_thumb.png" width="244" height="135" /></a></p>    <p>You may also want to try adding the account to the local Administrators, in case it is a file permissions issue (can’t see the TNSNAMES.ORA file). But remember to remove it later. It is much safer to find the directory it needs &amp; give the Service Account read access. Than to give it full Admin rights to the entire box.</p>    <p>&#160;</p> </blockquote>  <h4>Step 3: Try changing the Service Account of the SQL Service Analysis Services to logon with your account.</h4>  <p><strong><u>Note</u></strong>: Using your personal account to start any Windows Service is not a security '”Best Practice”. Once you’ve solved the issue, remember to create a Domain account for the OLAP service &amp; ensure SSAS is using it &amp; not yours. </p>  <blockquote>   <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/6153.Change%20OLAP%20Service%20properties_2.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/6153.Change-OLAP-Service-properties_5F00_2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Change OLAP Service properties" border="0" alt="Change OLAP Service properties" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/3581.Change%20OLAP%20Service%20properties_thumb.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/3581.Change-OLAP-Service-properties_5F00_thumb.png" width="644" height="230" /></a> </p>    <ul>     <li>Windows Start Menu: All Programs =&gt; Microsoft SQL Server 200?? =&gt; Configuration Tools =&gt; Configuration Manager </li>      <li>Choose Appropriate Instance of Analysis Services </li>      <li>R.Click Properties. </li>   </ul>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/5078.Change%20Service%20Account_2.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/5078.Change-Service-Account_5F00_2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Change Service Account" border="0" alt="Change Service Account" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/1374.Change%20Service%20Account_thumb.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/1374.Change-Service-Account_5F00_thumb.png" width="433" height="484" /></a> </p>    <p>Change from <strong>Built-in account:</strong> to <strong>This Account</strong> &amp; enter you own personal account. (the fictional account I created for this blog was “CENTRAL\DLEAN2&quot;) or you could use something more meaningful Account Name like “DomainName\SSASServiceAcount”.       <br />Note: Some sites create one Service account for all SQL Server services on all servers. Others have a separate account for each type of service (eg: Analysis, Reporting, Database). Others create a specific account for each SQL Service on each machine. There are pros &amp; cons with each approach. The right answer will vary depending on the scale &amp; interdependency of your environment, your security needs &amp; your process of managing accounts &amp; passwords. </p> </blockquote>  <h3>TIP: Oracle Datasource View configuration</h3>  <blockquote>   <p>You will notice this post applies to a variety of Connection error messages. You will get a slightly different wording depending on the values you used when configuring the “Impersonation Information” but the end result is the same, you can’t connect. </p>    <p>To check your connection, Open the DataSource you are using in BIDS.</p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/8737.Connection%20Manager_2.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/8737.Connection-Manager_5F00_2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Connection Manager" border="0" alt="Connection Manager" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/8233.Connection%20Manager_thumb.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/8233.Connection-Manager_5F00_thumb.png" width="462" height="484" /></a> </p>    <p>I’ve found both the Oracle &amp; the Microsoft OLE-DB providers work well. You will need to specify <u>your</u> Oracle User name as I do not believe Oracle supports Windows NT Integrated Security (bummer huh).       <br />(Note: I just invented the user name sepuser (September User) for this picture. It is not a special Oracle name)</p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/6180.Data%20Source%20Designer_2.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/6180.Data-Source-Designer_5F00_2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Data Source Designer" border="0" alt="Data Source Designer" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/8664.Data%20Source%20Designer_thumb.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/8664.Data-Source-Designer_5F00_thumb.png" width="398" height="484" /></a> <a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/2620.Impersonation%20Info_2.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/2620.Impersonation-Info_5F00_2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Impersonation Info" border="0" alt="Impersonation Info" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/12/71/metablogapi/1738.Impersonation%20Info_thumb.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-12-71-metablogapi/1738.Impersonation-Info_5F00_thumb.png" width="398" height="484" /></a> </p>    <p>In the Impersonation Information page. The <strong>Inherit</strong> option worked fine once I’d resolved the SSAS service account issue. You can also choose the other options but remember they are WINDOWS accounts. You have already typed in the Oracle Account info in the prior tab. This dialog is generic to all different types of OLE-DB providers &amp; different authentication schemes, what I’ve shown works most times in an Oracle world. </p> </blockquote>  <p>I trust this gets you up &amp; running quickly.</p>  <p>Dave</p>  <h3>Credits</h3>  <p>My thanks to <a title="A SQL Analysis Services demi-god" href="https://richardlees.com.au/Pages/RichardsWelcomePage.aspx" target="_blank">Richard Lees</a> and <a title="A SQL Analysis Services god. He&#39;s been creating &amp; designing it from mid &#39;90&#39;s to now" href="https://dwbi1.wordpress.com/whos-who-in-analysis-services/" target="_blank">Edward Melomed</a> for insight that helped me solve this issue. </p>]]></content:encoded>
    </item>
    <item>
      <title>Handy Links for SQL 2008 R2 &amp; .NET Development</title>
      <link>https://docs.microsoft.com/archive/blogs/davidlean/handy-links-for-sql-2008-r2-net-development</link>
      <pubDate>Tue, 03 Aug 2010 07:20:40 GMT</pubDate>
      <dc:creator><![CDATA[davele]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/davidlean/2010/08/03/handy-links-for-sql-2008-r2-net-development/</guid>
      <description><![CDATA[This post is not about a unique body of work, it is just a list of links to materials I’ve found...]]></description>
      <content:encoded><![CDATA[<p>This post is not about a unique body of work, it is just a list of links to materials I’ve found useful. I hope it may make it easier for me to point people here rather than have them write down or remember URL’s</p>  <p>If you are looking for SQL Add-in’s, Utilities, Sample Code &amp; education, perhaps you will find this useful to you too. </p>  <p>&#160;</p>  <p><u><font color="#ff00ff" size="4"><strong>SQL 2008 R2 Links</strong></font></u></p>  <p><a href="https://www.microsoft.com/sqlserver/2008/en/us/default.aspx" target="_blank">Microsoft SQL Server</a> – Official Microsoft SQL server Site    <br />&#160;&#160;&#160;&#160;&#160; <a href="https://www.microsoft.com/sqlserver/2008/en/us/R2-Next.aspx" target="_blank">Resources for 2008 R2</a> – Handy Resources (Marketing, Pricing &amp; Technical)</p>  <p><a href="https://www.microsoft.com/sqlserver/2008/en/us/default.aspx" target="_blank"></a></p>  <p><a title="The latest release of Value Add extras for SQL Server updated for R2" href="https://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=ceb4346f-657f-4d28-83f5-aae0c5c83d52" target="_blank">Microsoft® SQL Server® 2008 R2 Feature Pack</a> (7th Jun 10) includes :-</p>  <ul>   <li>SQL Server® 2008 R2 <strong>Best Practices Analyzer</strong></li>    <li>SQL Server® 2008 R2<strong> Upgrade Advisor</strong></li>    <li><strong></strong>SQL Server® 2008 R2 <strong>Books On-line       <br /></strong></li>    <li><a title="12 July 2010" href="https://www.microsoft.com/downloads/details.aspx?FamilyID=d3173a87-7c0d-40cc-a408-3d1a43ae4e33&amp;displaylang=en" target="_blank">SQL Server 2008 R2 <strong>Report Builder 3.0</strong></a></li>    <li><strong>PowerPivot</strong> for Microsoft® Excel &amp; Sharepoint</li>    <li>SQL Server® 2008 R2 <strong>Policies</strong></li>    <li>SQL Server® 2008 R2 <strong>Remote Blob Store</strong></li>    <li>SQL Server® 2008 R2 Native Client</li>    <li>SQL Server® 2008 R2 Command Line Utilities</li>    <li>SQL Server® 2008 R2 Shared Management Objects</li>    <li>SQL Server® 2008 R2 Analysis Management Objects</li>    <li>SQL Server® 2008 R2 ADOMD.NET</li>    <li>SQL Server® Service Broker External Activator for SQL Server® 2008 R2</li>    <li>SQL Server® 2008 <strong>Data Mining Add-ins</strong> for Microsoft® Office 2007</li>    <li>Sync Framework 2.0 Software Development Kit (SDK)</li>    <li>SQL Server® Compact 3.5 SP2</li>    <li>Windows <strong>PowerShell</strong> Extensions for SQL Server® 2008 R2</li>    <li><strong>Datamining Viewer Controls</strong> For Microsoft® SQL Server® 2008</li> </ul>  <blockquote>   <p><strong><u>Interoperability</u></strong></p> </blockquote>  <ul>   <li>Microsoft® SQL Server® <strong>Migration Assistant</strong></li>    <li><strong>JDBC</strong> Driver 3.0</li>    <li>Microsoft® SQL Server® Driver for <strong>PHP 1.1</strong></li>    <li>Microsoft® Connector 1.1 for <strong>SAP BW</strong> for SQL Server® 2008 R2</li>    <li>Microsoft® OLEDB Provider for <strong>DB2</strong></li>    <li>Microsoft® Analysis Services OLE DB Provider for Microsoft® SQL Server® 2008 R2</li>    <li>Microsoft® System CLR Types for SQL Server® 2008 R2      <br /></li> </ul>  <p><a title="12th April 2010" href="https://www.microsoft.com/downloads/details.aspx?familyid=A941C6B2-64DD-4D03-9CA7-4017A0D164FD&amp;displaylang=en" target="_blank">Microsoft Report Viewer 2010 Redistributable Package</a>&#160; <br />&#160;&#160;&#160;&#160;&#160; Lets you embed SQL Reports into your Windows Forms &amp; Web applications.     <br />&#160;&#160;&#160;&#160;&#160; <a href="https://blogs.msdn.com/b/brianhartman/archive/tags/reportviewer/" target="_blank">Brian Hartman's Report Viewer Blog</a> – Nice value add on adding reports into your application. </p>  <p><a title="26th May 2010" href="https://msftdbprodsamples.codeplex.com/releases/view/45907" target="_blank">Sample Databases for Microsoft SQL Server 2008 R2 (RTM)</a> – Updated Adventure Works, Northwind etc.</p>  <p>&#160;</p>  <p><u><font color="#ff00ff" size="4"><strong>SQL 2008 Performance Tools</strong></font></u></p>  <p>Not a comple list but a few of my favourites<strong>&#160;</strong></p>  <p><u>Replay Mark-up Language (RML) Utilities</u>    <br /><a href="https://www.microsoft.com/downloads/details.aspx?FamilyId=7EDFA95A-A32F-440F-A3A8-5160C8DBE926&amp;displaylang=en" target="_blank">&#160;&#160;&#160;&#160;&#160; RML Utilities for SQL Server (x86)</a>    <br />&#160;&#160;&#160;&#160;&#160; <a href="https://www.microsoft.com/downloads/details.aspx?familyid=B60CDFA3-732E-4347-9C06-2D1F1F84C342&amp;displaylang=en" target="_blank">RML Utilities for SQL Server (x64)</a>    <br />&#160;&#160;&#160;&#160;&#160; RML is an awesome utility for analysing load on SQL Server &amp; for creating a load.</p>  <p>&#160;</p>  <p><a href="https://sqlloadtest.codeplex.com/" target="_blank">SQL Load Test</a> – This is a handy utility for creating Visual Studio Load Tests from a SQL Profiler Trace. While far from a complete solution (as it doesn’t handle a lot of SQL Syntax) it does speed the process somewhat. I hope to enhance it in time. </p>  <p><a href="https://nodexl.codeplex.com/" target="_blank">NodeXL: Network Overview, Discovery and Exploration for Excel</a> – I find this handy to visualise the SQL Object Dependence within a database. ie: Quickly seeing that this SP calls 2 others &amp; they call a function or two that reference views &amp; tables. OR how many objects touch this table &amp; how many reference them all.     <br /></p>  <p>I see huge potential in using Visual Studio to perform Load tests, Stress Tests &amp; to ensure quality when you are rewriting TSQL code. Unfortunately it is missing a small number of features &amp;/or hooks that make the whole exercise marginal value. One day, soon I hope to have coded up extensions to fix those feature gaps. </p>  <p><a href="https://technet.microsoft.com/en-us/library/aa964139(SQL.90).aspx" target="_blank">Using Visual Studio 2005 to Perform Load Testing on a SQL Server 2005 Reporting Services Report Server</a> – Old article but helps setup Web Testing on SQL RS</p>  <p><a title="MSDN Magazine March 2009  Article" href="https://msdn.microsoft.com/en-us/magazine/dd483214.aspx" target="_blank">Introducing New Features In The VSTS Database Edition GDR</a></p>  <p><a href="https://msdn.microsoft.com/en-us/magazine/cc164243.aspx" target="_blank">Apply Test-Driven Development to your Database Projects</a> – This article shows how to write the 2 custom tests that make DB tests kinda useful. (Without them, don’t bother)</p>  <p><a title="VS 2005 = March 2007" href="https://msdn.microsoft.com/en-au/bb381703(VS.80).aspx" target="_blank">Database Unit Testing with Team Edition for Database Professionals</a> – Walk thru on creating a DB Unit Test.</p>  <p><a href="https://www.microsoft.com/downloads/details.aspx?FamilyID=73ba5038-8e37-4c8e-812b-db14ede2c354&amp;displaylang=en" target="_blank">Microsoft® Visual Studio Team System 2008 Database Edition Power Tools</a> – Tantalisingly nice add-in, likely to not work on your system as the GDR release broke much of it. </p>  <p><a title="I forgot I wrote this &amp; spent ages trying to firgure it out again. so linked it here :-)" href="https://blogs.msdn.com/b/davidlean/archive/2009/09/21/how-to-get-database-edition-power-tools-to-work-on-visual-studio-team-system-2008-database-edition-gdr.aspx" target="_blank">How to get Database Edition Power Tools to work on Visual Studio Team System 2008 Database Edition GDR</a></p>  <p><u><font color="#ff00ff" size="4"><strong></strong></font></u></p>  <p><u><font color="#ff00ff" size="4"><strong>SQL 2008 Samples, Training, Whitepapers</strong></font></u></p>  <p>&#160;</p>  <p><a href="https://sqlserversamples.codeplex.com/" target="_blank">Microsoft SQL Server Community Projects &amp; Samples</a> - Loads of great Code Samples</p>  <p>&#160;</p>  <p><a href="https://sqlcat.com/" target="_blank">SQL Server Customer Advisory Team - SQL Server Best Practices</a> – Whitepapers from the SQL Dev Team tasked with tuning the largest SQL Customer implementations.     <br />&#160;&#160;&#160;&#160;&#160; <a href="https://sqlcat.codeplex.com/releases/view/26601" target="_blank">SQLCAT Community Projects and Code Samples</a> – Nice set of handy add-ins</p>  <p>   <br /><a href="https://www.microsoft.com/downloads/details.aspx?familyid=FFFAAD6A-0153-4D41-B289-A3ED1D637C0D&amp;displaylang=en" target="_blank">SQL Server 2008 R2 Update for Developers Training Kit (June 2010 Update)</a>&#160; <br />&#160;&#160;&#160;&#160;&#160; Videos, Presentations, Demo’s &amp; Hands-On-Labs to get you up to speed on using the new capability of SQL Server 2008 R2. Includes the 2008 stuff too.</p> <a title="7th Jun 2010" href="https://www.microsoft.com/downloads/details.aspx?FamilyID=413E88F8-5966-4A83-B309-53B7B77EDF78&amp;displaylang=en" target="_blank">Windows Azure Platform Training Kit - June Update</a>   <br />&#160;&#160;&#160;&#160;&#160; Includes materials for SQL Azure. Videos, Presentations, Demo’s &amp; Hands-On-Labs.  <p><u><font color="#ff00ff" size="4"><strong></strong></font></u></p>  <p><u><font color="#ff00ff" size="4"><strong>General Dev Resources</strong></font></u></p>  <p><a title="Large numbers of Webcasts to watch on all topics" href="https://www.msteched.com/" target="_blank">Tech-Ed Online</a> Great technically deep Webcasts on a vast number of topics.</p>  <p><a href="https://msdn.microsoft.com/en-us/magazine/default.aspx" target="_blank">MSDN Magazine</a> – Good articles on new technologies that all developers should scan. </p>  <p>&#160;</p>  <p><u><font color="#ff00ff" size="4"><strong>Development Samples, Training, Whitepapers</strong></font></u></p>  <p><a href="https://1code.codeplex.com/" target="_blank">All-In-One Code Framework!</a> -&#160; framework and skeleton of Microsoft development techniques through typical sample codes in three popular programming languages (Visual C#, VB.NET, Visual C++).</p>  <p><a title="16th Jun 2010" href="https://www.microsoft.com/downloads/details.aspx?FamilyID=752CB725-969B-4732-A383-ED5740F02E93&amp;displaylang=en" target="_blank">Visual Studio 2010 and .NET Framework 4 Training Kit</a> – Presentations, Hands-On Labs, Demos on; Entiry Framework, C#, VB.NET, F#, ADO.NET Data Services, WPF, WCF, Parallel Extensions, Windows Workflow, ASP.NET, VS Team System &amp; More.</p>  <p><a href="https://code.msdn.microsoft.com/adonetefx" target="_blank">ADO.NET Entity Framework &amp; LINQ to Relational Data</a> – Samples for EF &amp; Link</p>  <p>&#160;</p>  <p><a title="Helps speed your dvelopment &amp; make it much more robust." href="https://entlib.codeplex.com/" target="_blank">Microsoft Patterns &amp; Practices - Enterprise Library</a> - The Microsoft Enterprise Library is a collection of reusable software components (application blocks) designed to assist software developers with common enterprise development challenges.    <br />&#160;&#160;&#160;&#160;&#160; <a href="https://entlibcontrib.codeplex.com/" target="_blank">Enterprise Library Contribution Project</a> – Extensions people have added to make it even easier. </p>  <p><u><font color="#000000" size="3"><strong></strong></font></u></p>  <p><u><font color="#000000" size="3"><strong>Silverlight</strong></font></u></p>  <p><a href="https://www.silverlight.net/" target="_blank">Microsoft Silverlight</a> – The Official Microsoft Silverlight Site. Good Tutorials, SDK, Downloads, Samples. etc</p>  <p><a title="16 April 2010" href="https://www.microsoft.com/downloads/details.aspx?familyid=24CEA29E-042E-41C9-AA16-684A0CA5F5DB&amp;displaylang=en" target="_blank">Silverlight 4 Training</a> – Detailed Whitepapers &amp; Labs to guide you to build business level applications</p>  <p><a href="https://code.msdn.microsoft.com/XAML/Wiki/View.aspx?title=Microsoft%20XAML%20Toolkit%20%20CTP%20-%20July%202010&amp;referringTitle=Home" target="_blank">Microsoft XAML Toolkit CTP - July 2010</a> - Microsoft XAML Toolkit is a set of libraries enabling easier manipulation and analysis of XAML for .NET 4.0 and Silverlight.</p>  <p><a title="Codeplex" href="https://blacklight.codeplex.com/" target="_blank">Blacklight - Controls for Designers!</a> Blacklight is a UX focused code sharing project. collection of controls, samples, visual assets and ideas that has been put together by User Experience designers and developers to both show you what the technology is capable of (from a UX point of view),</p>  <p>&#160;</p>  <p><a href="https://ajaxcontroltoolkit.codeplex.com/" target="_blank">ASP.NET AJAX Control Toolkit</a> rich set of 40+ controls that you can use to build highly responsive and interactive Ajax-enabled Web applications.</p>  <p><a href="https://msdn.microsoft.com/en-us/library/aa719467(v=VS.71).aspx" target="_blank">ASP.NET QuickStart</a> – Sample ASP Apps for Web folks</p>  <p>&#160;</p>  <p><a href="https://windowsclient.net/" target="_blank">WindowsClient.NET</a> – The Official Microsoft Site for Windows Forms &amp; Windows Presentation Foundation</p>  <p><a href="https://wpf.codeplex.com/" target="_blank">Windows Presentation Foundation (WPF)</a> - WPF Toolkit and the WPF Futures releases.</p>  <p>&#160;</p>  <p><a title="Regular Expressions" href="https://www.ultrapico.com/Expresso.htm" target="_blank">Expresso 3.0</a> – Brilliant tool to assist anyone writing Regular Expressions (REGEX). Essential for Data Cleansing, Screen Scraping &amp; a variety of SSIS uses. (free tool from Jim Hollenhorst of Ultrapico)</p>  <p>&#160;</p>  <p><a href="https://nodexl.codeplex.com/" target="_blank"></a></p>  <p><u><font color="#ff00ff" size="3"><strong>Excel Programming</strong></font></u></p>  <p><a href="https://www.excel-vba.com/excel-vba-contents.htm" target="_blank">VBA for Excel (Macros)</a> – Nice set of 33 lessons that cover how to get VBA Macros working in Excel.</p>  <p><a href="https://www.ozgrid.com/VBA/MiscVBA.htm" target="_blank">Excel VBA Macro Codes Tips &amp; Tricks</a></p>  <p><a href="https://www.angelfire.com/biz7/julian_s/julian/julians_macros.htm" target="_blank">Julian's Excel Macro (VBA) Tips for Beginners</a></p>  <p>---&lt; END &gt;---</p>  <p><strong><u></u></strong></p>  <p><strong><u>Thought for the post:</u></strong>     <br />If a Bedding Store is having a 50% off sale, &amp; you buy a Double bed, will they deliver a Single bed?     <br />If you buy a single bed with a “2&#160; for 1” coupon &amp; they deliver a Double bed, did you get what you paid for?</p>]]></content:encoded>
    </item>
    <item>
      <title>Apple headline I’d like to see ;-)</title>
      <link>https://docs.microsoft.com/archive/blogs/davidlean/apple-headline-id-like-to-see</link>
      <pubDate>Thu, 22 Apr 2010 17:13:48 GMT</pubDate>
      <dc:creator><![CDATA[davele]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/davidlean/2010/04/22/apple-headline-id-like-to-see/</guid>
      <description><![CDATA[Apple releases the iPatch for software Pirates ®&#160; (pronounced Arrrh … me hearty's!)  &#160;...]]></description>
      <content:encoded><![CDATA[<p>Apple releases the <strong>iPatch</strong> for software Pirates ®&#160; (pronounced Arrrh … me hearty's!)</p>  <p>&#160;</p>  <p>Note: This might not be true, but I think of it every time I hear the word iPad. Now you can too. </p>  <p>&#160;</p>  <p>If I worked for Apple it would only be a matter of time before they shipped a range of new products :-</p>  <ul>   <li><strong>iGlasses</strong> for the Elderly </li>    <li><strong>iWear</strong> for the rest of us</li>    <li>Fashion <strong>iWear</strong> for the Trendy</li>    <li><strong>spiGlasses</strong> for the Captains of the Pirate ships, oh and for 007 James Bond</li>    <li><strong>iSpy</strong> (with my little eye), for kids whose parents take them on long trips &amp; can’t afford to buy technical junk to keep them from talking to any other human. </li>    <li><strong>iCanSeeYou</strong> for people who knock on doors of residents who pretend they aren’t home.</li>    <li><strong>iKentinaturner</strong> similar to an iPod but it only plays “Nutbush City Limits” &amp; “Proud Mary”.</li> </ul>  <p>(So now you know what I think about while watching 100’s of Millions of rows load into a PowerPivot spreadsheet. How cool is that? more on that later)</p>]]></content:encoded>
    </item>
    <item>
      <title>SQL 2008 R2 RTM’s check out the free training</title>
      <link>https://docs.microsoft.com/archive/blogs/davidlean/sql-2008-r2-rtms-check-out-the-free-training</link>
      <pubDate>Thu, 22 Apr 2010 03:10:45 GMT</pubDate>
      <dc:creator><![CDATA[davele]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/davidlean/2010/04/22/sql-2008-r2-rtms-check-out-the-free-training/</guid>
      <description><![CDATA[Yes SQL 2008 R2 has reached a major milestone, on the 21st Apr 2010 the news went to the world...]]></description>
      <content:encoded><![CDATA[<p>Yes SQL 2008 R2 has reached a major milestone, on the 21st Apr 2010 the news went to the world SQL2008 R2 has gone “Release To Manufacturing (RTM)”. This means that the Development Team (&amp; many others) have signed it off as complete. It then takes a few days / weeks to get it into the schedules of the manufacturing plants to start pressing the DVD’s.&#160; </p>  <p>&#160;</p>  <p>While you are waiting for it to be available for download via MSDN or delivered to you on a DVD fulfilment. Check out <a title="Free SQL Webcasts, Whitepapers &amp; Resources" href="https://www.microsoft.com/sqlserver/tour/en/default.aspx" target="_blank"><font size="3"><strong>The SQL Server R2 Digital Tour</strong></font></a></p>  <blockquote>   <p>What will you find there? Links to a whole host of resources, including</p>    <ol>     <li>The SQL 2008/R2 Resource Kit</li>      <li>SQL Server 2008 R2 Update for Developers Training Kit</li>      <li>a Small eBook listing all the new features, so I will not repeat it here.</li>      <li><u><strong>Webcasts</strong> (inc the following)</u></li>   </ol>    <ul>     <li>An Introduction to SQL Server 2008 R2</li>      <li>SQL Server 2008 R2 Overview</li>      <li>Introduction to SQL Azure</li>      <li>Lower Costs through BI Consolidation</li>      <li>Migrating from Oracle to SQL Server</li>      <li>SSRS and Report Builder 3.0</li>      <li>PowerPivot for Excel and SharePoint </li>      <li>Master Data Services</li>      <li>Business Continuity with SQL Server and Windows Server 2008 R2 Hyper-V Live Migration</li>      <li>Application and Multi-Server Management</li>      <li>Parallel Data Warehouse&#160;&#160;&#160;&#160; <br />Develop Rich Reporting Solutions</li>      <li>StreamInsight Complex Event Processing </li>      <li>SQL Server 2008 R2 and BizTalk Server</li>   </ul> </blockquote>  <p>Don’t forget to check out the new SQL Server 2008 R2 PowerPivot for Excel. The BI capabilities for End Users are truly ground-breaking, &amp; like Microsoft Office 2010 it is also ready to go now. </p>  <p>enjoy, </p>  <p>&#160;</p>  <p>PS: In case you are still have spare time, check out the Visual Studio 2010 it is really nice. Don’t overlook the features for testing your database.</p>]]></content:encoded>
    </item>
    <item>
      <title>Hey Network installers, need a Cool way to cut a square hole in a skirting board?</title>
      <link>https://docs.microsoft.com/archive/blogs/davidlean/hey-network-installers-need-a-cool-way-to-cut-a-square-hole-in-a-skirting-board</link>
      <pubDate>Wed, 07 Apr 2010 06:28:15 GMT</pubDate>
      <dc:creator><![CDATA[davele]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/davidlean/2010/04/07/hey-network-installers-need-a-cool-way-to-cut-a-square-hole-in-a-skirting-board/</guid>
      <description><![CDATA[While this has little to do with Data &amp; I am far from a DIY dude. Just thought I’d mention the...]]></description>
      <content:encoded><![CDATA[<p>While this has little to do with Data &amp; I am far from a DIY dude. Just thought I’d mention the <strong>Bosch PMF180E All Rounder</strong>. Just cause it is such a handy tool.</p>  <p>I had some rot in my wooden deck &amp; needed to cut out some wooden panels precisely on the joists. I tried a chisel &amp; a whole lot of BS. It took me forever just to do one &amp; I botched it. So I put it on the backburner, went back to my computer &amp; did nothing more for months.    <br /></p>  <p>This Easter, my wife got very enthusiastic about me finishing the job. And so, with her by my side, I stumbled across this Power tool at the local H/W store (Bunnings).&#160; It has a square saw attachment that you can see sticking out of the front in the picture below. It is so cool, cuts a straight line directly into wood, as fast as a hot knife into butter. Well as fast as you’d drill a hole in wood anyway.</p>  <p>It also has a ton of attachments I don’t care about; to sand, cut pipes, tiles, cut things flush etc.<a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/davidlean/WindowsLiveWriter/HeyNetworkinstallersneedaCoolwaytocutasq_149E2/Bosch%20PMF180E.jpg" original-url="https://blogs.msdn.com/blogfiles/davidlean/WindowsLiveWriter/HeyNetworkinstallersneedaCoolwaytocutasq_149E2/Bosch%20PMF180E.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Bosch PMF180E" border="0" alt="Bosch PMF180E" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/davidlean/WindowsLiveWriter/HeyNetworkinstallersneedaCoolwaytocutasq_149E2/Bosch%20PMF180E_thumb.jpg" original-url="https://blogs.msdn.com/blogfiles/davidlean/WindowsLiveWriter/HeyNetworkinstallersneedaCoolwaytocutasq_149E2/Bosch%20PMF180E_thumb.jpg" width="244" height="168" /></a> </p>  <p><font color="#0000ff">So if you install Network Ports in skirting boards or have any other reason to cut high precision rectangular holes in wood, plaster walls or similar, this is definitely something you should check out.</font> </p>  <p>Be warned, cutting with this thing is kinda fun. The guy who sold me this was very insistent on my owning a modern cable &amp; pipe detector. My wooden deck was outside so I didn’t have to worry about water or power. So I didn’t get one. But can now see why he thought it wise to own one. This thing would cut thru copper pipes &amp; cables like they weren’t there. ;-)</p>]]></content:encoded>
    </item>
  </channel>
</rss>