<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>SQL Server Appendix Z</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/sql_server_appendix_z/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/sql_server_appendix_z/feed.xml</link>
    <description>Digging into the fringe cases that didn&amp;#039;t get a chapter in the SQL Server books...</description>
    <lastBuildDate>Wed, 17 Apr 2019 03:51:58 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>SQL Server: Variables, Parameters or Literals? Or... Constants?</title>
      <link>https://docs.microsoft.com/archive/blogs/sql_server_appendix_z/sql-server-variables-parameters-or-literals-or-constants</link>
      <pubDate>Mon, 16 Sep 2013 17:40:00 GMT</pubDate>
      <dc:creator><![CDATA[Jared Ko]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sql_server_appendix_z/2013/09/16/sql-server-variables-parameters-or-literals-or-constants/</guid>
      <description><![CDATA[The age-old question
"Should I use Variables, Parameters, or Literals in my code?" We've all seen...]]></description>
      <content:encoded><![CDATA[<h2><strong style="font-size: 1.5em;">The age-old question</strong></h2>
<p><strong></strong>"Should I use Variables, Parameters, or Literals in my code?" We've all seen the pros and cons for each of them and had to choose the option with the least negative impact. What if I told you there was a fourth option?<br /><br />For years, I wished SQL Server would support constants, a value that you could declare at the database level, that would allow the best query plan and still be simple to change. Sadly, I can't say that they're being introduced (not that I'm aware of). But with a little work, we can duplicate their functionality. For lack of a better term, I'll be referring to it as a Pseudo-Constant.</p>
<p>Using AdventureWorks, consider a scenario where the Shipping department need a special report for all "Overnight Shipping" orders. We'd typically choose one of three solutions for for implementing this query:</p>
<h4>Using Variables</h4>
<div style="color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px; white-space: nowrap;"><span style="background: #ffffff; color: #0000ff;">DECLARE</span><span style="background: #ffffff; color: #000000;"> @ShipMethodID </span><span style="background: #ffffff; color: #0000ff;">INT</span><br /> <span style="background: #ffffff; color: #0000ff;">SELECT</span><span style="background: #ffffff; color: #000000;"> @ShipMethodID </span><span style="background: #ffffff; color: #808080;">=</span><span style="background: #ffffff; color: #000000;"> m</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">ShipMethodID</span><br /> <span style="background: #ffffff; color: #0000ff;">FROM</span><span style="background: #ffffff; color: #000000;"> Purchasing</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">ShipMethod m</span><br /> <span style="background: #ffffff; color: #0000ff;">WHERE</span><span style="background: #ffffff; color: #000000;"> m</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">Name </span><span style="background: #ffffff; color: #808080;">=&nbsp;</span><span style="background: #ffffff; color: #ff0000;">'OVERNIGHT J-FAST'</span><br /> <br /> <span style="background: #ffffff; color: #0000ff;">SELECT&nbsp;</span><span style="background: #ffffff; color: #808080;">*</span><br /> <span style="background: #ffffff; color: #0000ff;">FROM</span><span style="background: #ffffff; color: #000000;"> Sales</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">SalesOrderHeader h</span><br /> <span style="background: #ffffff; color: #0000ff;">WHERE</span><span style="background: #ffffff; color: #000000;"> h</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">ShipMethodID </span><span style="background: #ffffff; color: #808080;">=</span><span style="background: #ffffff; color: #000000;"> @ShipMethodID</span></div>
</div>
<pre>&nbsp;</pre>
<h4>Using Literals</h4>
<div style="color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px; white-space: nowrap;"><span style="background: #ffffff; color: #0000ff;">SELECT&nbsp;</span><span style="background: #ffffff; color: #808080;">*</span><br /> <span style="background: #ffffff; color: #0000ff;">FROM</span><span style="background: #ffffff; color: #000000;"> Sales</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">SalesOrderHeader h</span><br /> <span style="background: #ffffff; color: #0000ff;">WHERE</span><span style="background: #ffffff; color: #000000;"> h</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">ShipMethodID </span><span style="background: #ffffff; color: #808080;">=</span><span style="background: #ffffff; color: #000000;"> 4 </span><span style="background: #ffffff; color: #008000;">-- OVERNIGHT J-FAST</span></div>
</div>
<p>&nbsp;</p>
<h4>Using Stored Procedure Parameters</h4>
<div style="color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px; white-space: nowrap;"><span style="background: #ffffff; color: #0000ff;">CREATE&nbsp;</span><span style="background: #ffffff; color: #0000ff;">PROCEDURE</span><span style="background: #ffffff; color: #000000;"> GetShippingData</span><span style="background: #ffffff; color: #808080;">(</span><span style="background: #ffffff; color: #000000;">@ShipMethodID </span><span style="background: #ffffff; color: #0000ff;">INT</span><span style="background: #ffffff; color: #808080;">)</span><br /> <span style="background: #ffffff; color: #0000ff;">AS</span><br /> <span style="background: #ffffff; color: #0000ff;">SELECT&nbsp;</span><span style="background: #ffffff; color: #808080;">*&nbsp;</span><span style="background: #ffffff; color: #0000ff;">FROM</span><span style="background: #ffffff; color: #000000;"> Sales</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">SalesOrderHeader h </span><br /> <span style="background: #ffffff; color: #0000ff;">WHERE</span><span style="background: #ffffff; color: #000000;"> ShipMethodID </span><span style="background: #ffffff; color: #808080;">=</span><span style="background: #ffffff; color: #000000;"> @ShipMethodID</span></div>
</div>
<p>While a constant would rarely replace the need for parameters, it's worth mentioning their behavior for the sake of comparison. Through a feature called, "parameter sniffing", parameters give&nbsp;the query optimizer the best value for your first compiled execution but can often cause issues with subsequent calls that don't represent data of a similar cardinality. Among other places, parameter sniffing is discussed <a title="here" href="https://www.simple-talk.com/sql/t-sql-programming/parameter-sniffing/">here</a> and <a title="here" href="http://www.brentozar.com/archive/2013/06/the-elephant-and-the-mouse-or-parameter-sniffing-in-sql-server/">here</a>.</p>
<h2>Using Pseudo-Constants</h2>
<p class="auto-style1">Like a real constant, the pseudo-constant doesn't replace the need for parameters or variables. Instead, it's something that you might consider when you want the performance of a literal without the overhead maintenance of updating hundreds of procedures when a change is required. <br /><br /> <strong>Implementation</strong>:</p>
<p class="auto-style1">Pseudo-Constants are not variables or parameters. Instead, they're simply views with one row, and enough columns to support your constants. With these simple rules, the SQL Engine completely ignores the value of the view but still builds an execution plan based on its value. <strong>The execution plan doesn't even show a join to the view!</strong></p>
<p>To show its true power, we'll have to add some data to AdventureWorks database. I'm using the <a href="http://msftdbprodsamples.codeplex.com/releases/view/55330"> AdventureWorks2012 download</a> from CodePlex and updating the SalesOrderHeader table to include a wider variety of data.</p>
<p><strong>Data and Index Changes</strong></p>
<p>[Sales].[SalesOrderHeader] currenly uses two of the five ship methods, which doesn't give us enough uniqueness of data. We're also missing an index on ShipMethodID so we'll make a few adjustments:</p>
<div style="color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px; white-space: nowrap;"><span style="background: #ffffff; color: #008000;">-- Change 1000 "XRQ - TRUCK GROUND" rows to "ZY - EXPRESS"</span><br /><span style="background: #ffffff; color: #ff00ff;">UPDATE</span><span style="background: #ffffff; color: #000000;"> h </span><span style="background: #ffffff; color: #0000ff;">SET</span><span style="background: #ffffff; color: #000000;"> h</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">ShipMethodID </span><span style="background: #ffffff; color: #808080;">=</span><span style="background: #ffffff; color: #000000;"> 2</span><br /> <span style="background: #ffffff; color: #0000ff;">FROM</span><span style="background: #ffffff; color: #000000;"> Sales</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">SalesOrderHeader h</span><br /> <span style="background: #ffffff; color: #0000ff;">WHERE</span><span style="background: #ffffff; color: #000000;"> h</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">SalesOrderID </span><span style="background: #ffffff; color: #808080;">IN</span><span style="background: #ffffff; color: #808080;">(</span><span style="background: #ffffff; color: #0000ff;">SELECT&nbsp;</span><span style="background: #ffffff; color: #0000ff;">TOP</span><span style="background: #ffffff; color: #000000;"> 1000 SalesOrderID </span><br /> &nbsp;&nbsp;<span style="background: #ffffff; color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="background: #ffffff; color: #0000ff;">FROM&nbsp;</span><span style="background: #ffffff; color: #000000;">Sales</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">SalesOrderHeader </span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="background: #ffffff; color: #0000ff;">WHERE</span><span style="background: #ffffff; color: #000000;"> ShipMethodID </span><span style="background: #ffffff; color: #808080;">=</span><span style="background: #ffffff; color: #000000;"> 1 </span><span style="background: #ffffff; color: #0000ff;">ORDER&nbsp;</span><span style="background: #ffffff; color: #0000ff;">BY&nbsp;</span><span style="background: #ffffff; color: #ff00ff;">newid</span><span style="background: #ffffff; color: #808080;">())</span><br /> <br /> <span style="background: #ffffff; color: #008000;">-- Change 100 "XRQ - TRUCK GROUND" rows to "OVERSEAS - DELUXE"</span><br /><span style="background: #ffffff; color: #ff00ff;">UPDATE</span><span style="background: #ffffff; color: #000000;"> h </span><span style="background: #ffffff; color: #0000ff;">SET</span><span style="background: #ffffff; color: #000000;"> h</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">ShipMethodID </span><span style="background: #ffffff; color: #808080;">=</span><span style="background: #ffffff; color: #000000;"> 3 </span><br /> <span style="background: #ffffff; color: #0000ff;">FROM</span><span style="background: #ffffff; color: #000000;"> Sales</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">SalesOrderHeader h</span><br /> <span style="background: #ffffff; color: #0000ff;">WHERE</span><span style="background: #ffffff; color: #000000;"> h</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">SalesOrderID </span><span style="background: #ffffff; color: #808080;">IN</span><span style="background: #ffffff; color: #808080;">(</span><span style="background: #ffffff; color: #0000ff;">SELECT&nbsp;</span><span style="background: #ffffff; color: #0000ff;">TOP</span><span style="background: #ffffff; color: #000000;"> 100 SalesOrderID </span><br /> &nbsp;&nbsp;<span style="background: #ffffff; color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="background: #ffffff; color: #0000ff;">FROM</span><span style="background: #ffffff; color: #000000;"> Sales</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">SalesOrderHeader </span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="background: #ffffff; color: #0000ff;">WHERE</span><span style="background: #ffffff; color: #000000;"> ShipMethodID </span><span style="background: #ffffff; color: #808080;">=</span><span style="background: #ffffff; color: #000000;"> 1 </span><span style="background: #ffffff; color: #0000ff;">ORDER&nbsp;</span><span style="background: #ffffff; color: #0000ff;">BY&nbsp;</span><span style="background: #ffffff; color: #ff00ff;">newid</span><span style="background: #ffffff; color: #808080;">())</span><br /> <br /> <span style="background: #ffffff; color: #008000;">-- Change 10 "XRQ - TRUCK GROUND" rows to "OVERNIGHT J-FAST"</span><br /><span style="background: #ffffff; color: #ff00ff;">UPDATE</span><span style="background: #ffffff; color: #000000;"> h </span><span style="background: #ffffff; color: #0000ff;">SET</span><span style="background: #ffffff; color: #000000;"> h</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">ShipMethodID </span><span style="background: #ffffff; color: #808080;">=</span><span style="background: #ffffff; color: #000000;"> 4 </span><br /> <span style="background: #ffffff; color: #0000ff;">FROM</span><span style="background: #ffffff; color: #000000;"> Sales</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">SalesOrderHeader h</span><br /> <span style="background: #ffffff; color: #0000ff;">WHERE</span><span style="background: #ffffff; color: #000000;"> h</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">SalesOrderID </span><span style="background: #ffffff; color: #808080;">IN</span><span style="background: #ffffff; color: #808080;">(</span><span style="background: #ffffff; color: #0000ff;">SELECT&nbsp;</span><span style="background: #ffffff; color: #0000ff;">TOP</span><span style="background: #ffffff; color: #000000;"> 10 SalesOrderID </span><br /> &nbsp;&nbsp;<span style="background: #ffffff; color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="background: #ffffff; color: #0000ff;">FROM&nbsp;</span><span style="background: #ffffff; color: #000000;">Sales</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">SalesOrderHeader </span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="background: #ffffff; color: #0000ff;">WHERE</span><span style="background: #ffffff; color: #000000;"> ShipMethodID </span><span style="background: #ffffff; color: #808080;">=</span><span style="background: #ffffff; color: #000000;"> 1 </span><span style="background: #ffffff; color: #0000ff;">ORDER&nbsp;</span><span style="background: #ffffff; color: #0000ff;">BY&nbsp;</span><span style="background: #ffffff; color: #ff00ff;">newid</span><span style="background: #ffffff; color: #808080;">())</span><br /> <br /> <span style="background: #ffffff; color: #008000;">-- Add an index to ShipMethodId</span><br /> <span style="background: #ffffff; color: #0000ff;">CREATE&nbsp;</span><span style="background: #ffffff; color: #0000ff;">INDEX</span><span style="background: #ffffff; color: #000000;"> ix_Sales_SalesOrderHeader_ShipMethodId </span><span style="background: #ffffff; color: #0000ff;">ON</span><span style="background: #ffffff; color: #000000;"> Sales</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">SalesOrderHeader</span><span style="background: #ffffff; color: #808080;">(</span><span style="background: #ffffff; color: #000000;">ShipMethodID</span><span style="background: #ffffff; color: #808080;">)</span></div>
</div>
&nbsp;
<h4><strong>Pseudo-Constant creation</strong></h4>
<p>Our next step is to generate our Pseudo-Constants. As described above, we will create a table for each constant we require in our code. We'll also create a schema to keep things organized. This is not required but I find it improves readability. The data we're creating reflects the data in [Purchasing].[ShipMethod]</p>
<table border="1">
<tbody>
<tr><th>ShipMethodID</th><th>Name</th></tr>
<tr>
<td>1</td>
<td>XRQ - TRUCK GROUND</td>
</tr>
<tr>
<td>2</td>
<td>ZY - EXPRESS</td>
</tr>
<tr>
<td>3</td>
<td>OVERSEAS - DELUXE</td>
</tr>
<tr>
<td>4</td>
<td>OVERNIGHT J-FAST</td>
</tr>
<tr>
<td>5</td>
<td>CARGO TRANSPORT 5</td>
</tr>
</tbody>
</table>
<div style="color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px; white-space: nowrap;">&nbsp;</div>
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px; white-space: nowrap;"><span style="background: #ffffff; color: #0000ff;">CREATE&nbsp;</span><span style="background: #ffffff; color: #0000ff;">SCHEMA</span><span style="background: #ffffff; color: #000000;"> ShipMethod</span><br /> <span style="background: #ffffff; color: #0000ff;">GO</span><br /> <span style="background: #ffffff; color: #008000;">-- Each view can only have one row.</span><br /> <span style="background: #ffffff; color: #008000;">-- Create one column for each desired constant.</span><br /> <span style="background: #ffffff; color: #008000;">-- Each column is restricted to a single value.</span><br /> <br /> <span style="background: #ffffff; color: #0000ff;">CREATE&nbsp;</span><span style="background: #ffffff; color: #0000ff;">VIEW</span><span style="background: #ffffff; color: #000000;"> ShipMethod</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">ShipMethodID </span><span style="background: #ffffff; color: #0000ff;">AS</span><br /> <span style="background: #ffffff; color: #0000ff;">SELECT&nbsp;</span><span style="background: #ffffff; color: #ff00ff;">CAST</span><span style="background: #ffffff; color: #808080;">(</span><span style="background: #ffffff; color: #000000;">1 </span><span style="background: #ffffff; color: #0000ff;">AS&nbsp;</span><span style="background: #ffffff; color: #0000ff;">INT</span><span style="background: #ffffff; color: #808080;">)&nbsp;</span><span style="background: #ffffff; color: #0000ff;">AS</span><span style="background: #ffffff; color: #000000;"> [XRQ - TRUCK GROUND]</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="background: #ffffff; color: #808080;">,</span><span style="background: #ffffff; color: #ff00ff;">CAST</span><span style="background: #ffffff; color: #808080;">(</span><span style="background: #ffffff; color: #000000;">2 </span><span style="background: #ffffff; color: #0000ff;">AS&nbsp;</span><span style="background: #ffffff; color: #0000ff;">INT</span><span style="background: #ffffff; color: #808080;">)&nbsp;</span><span style="background: #ffffff; color: #0000ff;">AS</span><span style="background: #ffffff; color: #000000;"> [ZY - EXPRESS]</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="background: #ffffff; color: #808080;">,</span><span style="background: #ffffff; color: #ff00ff;">CAST</span><span style="background: #ffffff; color: #808080;">(</span><span style="background: #ffffff; color: #000000;">3 </span><span style="background: #ffffff; color: #0000ff;">AS&nbsp;</span><span style="background: #ffffff; color: #0000ff;">INT</span><span style="background: #ffffff; color: #808080;">)&nbsp;</span><span style="background: #ffffff; color: #0000ff;">AS</span><span style="background: #ffffff; color: #000000;"> [OVERSEAS - DELUXE]</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="background: #ffffff; color: #808080;">,</span><span style="background: #ffffff; color: #ff00ff;">CAST</span><span style="background: #ffffff; color: #808080;">(</span><span style="background: #ffffff; color: #000000;">4 </span><span style="background: #ffffff; color: #0000ff;">AS&nbsp;</span><span style="background: #ffffff; color: #0000ff;">INT</span><span style="background: #ffffff; color: #808080;">)&nbsp;</span><span style="background: #ffffff; color: #0000ff;">AS</span><span style="background: #ffffff; color: #000000;"> [OVERNIGHT J-FAST]</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="background: #ffffff; color: #808080;">,</span><span style="background: #ffffff; color: #ff00ff;">CAST</span><span style="background: #ffffff; color: #808080;">(</span><span style="background: #ffffff; color: #000000;">5 </span><span style="background: #ffffff; color: #0000ff;">AS&nbsp;</span><span style="background: #ffffff; color: #0000ff;">INT</span><span style="background: #ffffff; color: #808080;">)&nbsp;</span><span style="background: #ffffff; color: #0000ff;">AS</span><span style="background: #ffffff; color: #000000;"> [CARGO TRANSPORT 5]</span></div>
</div>
<p>&nbsp;</p>
<p><strong>Testing Our Pseudo-Constants</strong></p>
<p>Now that our view is in place, we can compare the overhead of a pseudo-constant with that of a variable and a literal. We'll start by turning on STATISTICS IO and then running the most selective query (OVERNIGHT J-FAST) against each implementation.</p>
<p>&nbsp;</p>
<div style="color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px; white-space: nowrap;"><span style="background: #ffffff; color: #0000ff;">SET&nbsp;</span><span style="background: #ffffff; color: #0000ff;">NOCOUNT&nbsp;</span><span style="background: #ffffff; color: #0000ff;">ON</span><br /> <span style="background: #ffffff; color: #0000ff;">SET&nbsp;</span><span style="background: #ffffff; color: #0000ff;">STATISTICS</span><span style="background: #ffffff; color: #0000ff;">IO&nbsp;</span><span style="background: #ffffff; color: #0000ff;">ON</span></div>
</div>
<p>&nbsp;</p>
<div style="color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px; white-space: nowrap;"><span style="background: #ffffff; color: #008000;">-- Execute as a variable</span><br /> <span style="background: #ffffff; color: #0000ff;">DECLARE</span><span style="background: #ffffff; color: #000000;"> @ShipMethodID </span><span style="background: #ffffff; color: #0000ff;">INT</span><br /> <span style="background: #ffffff; color: #0000ff;">SELECT</span><span style="background: #ffffff; color: #000000;"> @ShipMethodID </span><span style="background: #ffffff; color: #808080;">=</span><span style="background: #ffffff; color: #000000;"> m</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">ShipMethodID</span><br /> <span style="background: #ffffff; color: #0000ff;">FROM</span><span style="background: #ffffff; color: #000000;"> Purchasing</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">ShipMethod m</span><br /> <span style="background: #ffffff; color: #0000ff;">WHERE</span><span style="background: #ffffff; color: #000000;"> m</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">Name </span><span style="background: #ffffff; color: #808080;">=</span><span style="background: #ffffff; color: #ff0000;">'OVERNIGHT J-FAST'</span><br /> <br /> <span style="background: #ffffff; color: #0000ff;">SELECT</span><span style="background: #ffffff; color: #808080;">*</span><br /> <span style="background: #ffffff; color: #0000ff;">FROM</span><span style="background: #ffffff; color: #000000;"> Sales</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">SalesOrderHeader h</span><br /> <span style="background: #ffffff; color: #0000ff;">WHERE</span><span style="background: #ffffff; color: #000000;"> h</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">ShipMethodID </span><span style="background: #ffffff; color: #808080;">=</span><span style="background: #ffffff; color: #000000;"> @ShipMethodID</span></div>
</div>
<p>&nbsp;</p>
<div style="color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background-color: #e0e0e0; max-height: 300px; overflow: auto; padding: 2px 5px; white-space: nowrap;">Table 'ShipMethod'. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.<br /> Table 'SalesOrderHeader'. Scan count 1, logical reads 693, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.</div>
</div>
<p>&nbsp;</p>
<div style="color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px; white-space: nowrap;"><span style="background: #ffffff; color: #008000;">-- Execute As JOIN</span><br /> <span style="background: #ffffff; color: #0000ff;">SELECT</span><span style="background: #ffffff; color: #000000;"> h</span><span style="background: #ffffff; color: #808080;">.*</span><br /> <span style="background: #ffffff; color: #0000ff;">FROM</span><span style="background: #ffffff; color: #000000;"> Sales</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">SalesOrderHeader h </span><br /> <span style="background: #ffffff; color: #808080;">JOIN</span><span style="background: #ffffff; color: #000000;"> Purchasing</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">ShipMethod sm</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span style="background: #ffffff; color: #0000ff;">ON</span><span style="background: #ffffff; color: #000000;"> h</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">ShipMethodID </span><span style="background: #ffffff; color: #808080;">=</span><span style="background: #ffffff; color: #000000;"> sm</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">ShipMethodID</span><br /> <span style="background: #ffffff; color: #0000ff;">WHERE</span><span style="background: #ffffff; color: #000000;"> sm</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">Name </span><span style="background: #ffffff; color: #808080;">=</span><span style="background: #ffffff; color: #ff0000;">'OVERNIGHT J-FAST'</span></div>
</div>
<p>&nbsp;</p>
<div style="color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background-color: #e0e0e0; max-height: 300px; overflow: auto; padding: 2px 5px; white-space: nowrap;">Table 'Worktable'. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.<br /> Table 'ShipMethod'. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.<br /> Table 'SalesOrderHeader'. Scan count 1, logical reads 693, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.</div>
</div>
<p>&nbsp;</p>
<div style="color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px; white-space: nowrap;"><span style="background: #ffffff; color: #008000;">-- Execute as a literal</span><br /> <span style="background: #ffffff; color: #0000ff;">SELECT&nbsp;</span><span style="background: #ffffff; color: #808080;">*&nbsp;</span><span style="background: #ffffff; color: #0000ff;">FROM</span><span style="background: #ffffff; color: #000000;"> Sales</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">SalesOrderHeader h </span><br /> <span style="background: #ffffff; color: #0000ff;">WHERE</span><span style="background: #ffffff; color: #000000;"> ShipMethodID </span><span style="background: #ffffff; color: #808080;">=</span><span style="background: #ffffff; color: #000000;"> 4 </span><span style="background: #ffffff; color: #008000;">-- OVERNIGHT J-FAST</span></div>
</div>
<p>&nbsp;</p>
<div style="color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background-color: #e0e0e0; max-height: 300px; overflow: auto; padding: 2px 5px; white-space: nowrap;">Table 'SalesOrderHeader'. Scan count 1, logical reads 32, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.</div>
</div>
<p>&nbsp;</p>
<div style="color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px; white-space: nowrap;"><span style="background: #ffffff; color: #0000ff;">SELECT</span><span style="background: #ffffff; color: #000000;"> h</span><span style="background: #ffffff; color: #808080;">.*</span><br /> <span style="background: #ffffff; color: #0000ff;">FROM</span><span style="background: #ffffff; color: #000000;"> Sales</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">SalesOrderHeader h </span><br /> <span style="background: #ffffff; color: #808080;">JOIN</span><span style="background: #ffffff; color: #000000;"> ShipMethod</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">ShipMethodID const </span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span style="background: #ffffff; color: #0000ff;">ON</span><span style="background: #ffffff; color: #000000;"> h</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">ShipMethodID </span><span style="background: #ffffff; color: #808080;">=</span><span style="background: #ffffff; color: #000000;"> const</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">[OVERNIGHT J-FAST]</span></div>
</div>
<p>&nbsp;</p>
<div style="color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background-color: #e0e0e0; max-height: 300px; overflow: auto; padding: 2px 5px; white-space: nowrap;">Table 'SalesOrderHeader'. Scan count 1, logical reads 32, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.</div>
</div>
<p>&nbsp;</p>
<p><strong>First Observations</strong></p>
<p>There are two interesting things we see from STATISTICS IO output. <br /> 1. While the use of a standard JOIN or a variable show reads from the ShipMethod table, there are no observable reads from using the view.<br /> 2. Compared to literal and Pseudo-Constant, the logical reads against SalesOrderHeader are significantly higher with a standard JOIN or a variable.</p>
<p><strong>Execution Plans</strong></p>
<p>We can see here, that using a variable results in a clustered index scan. Since the value of @ShipMethodID is not known at compile time, the SQL engine has estimated that 104488.3 rows (one third of the total 31465 rows) will be returned. There are a lot of articles that describe this behavior including <a title="a great one by Kalen Delaney" href="http://sqlmag.com/t-sql/optimizing-variables-and-parameters">a great one by Kalen Delaney </a>so I'm not going to cover it again here. I'll only mention that this is expected behavior when using variables in a query.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/04/0572.PlanFromVariable.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-04/0572.PlanFromVariable.jpg"><img title="Execution Plan From Variable" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/04/0572.PlanFromVariable.jpg" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-04/0572.PlanFromVariable.jpg" alt="Execution Plan From Variable" /></a></p>
<p>&nbsp;</p>
<p>More interestingly, using Pseudo-Constants gives us the exact same execution plan as using a literal. The estimated and actual number of rows are a match because we know the value of ShipMethodID at compile-time.</p>
<p>&nbsp;</p>
<p>&nbsp;<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/04/0045.PlanFromConstant.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-04/0045.PlanFromConstant.jpg"><img title="Execution Plan From Pseudo-Constant" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/04/0045.PlanFromConstant.jpg" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-04/0045.PlanFromConstant.jpg" alt="Execution Plan From Pseudo-Constant" /></a></p>
<p>&nbsp;</p>
<p>Looking at the Index Seek operation, we even see that SQL Server is using the literal value 4 to determine the execution plan.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/04/2388.Seek%20Predicates.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-04/2388.Seek-Predicates.jpg"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/04/2388.Seek%20Predicates.jpg" original-url="http://blogs.msdn.com/resized-image.ashx/__size/300x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-04/2388.Seek-Predicates.jpg" alt="" border="0" /></a></p>
<p><strong>But Why Bother? Why not use Literals?</strong></p>
<p>&nbsp;So why not just use literal values? On the surface, it seems like Pseudo-Constants are a lot of work with no additional benefit, but we get some terrific advantages in medium-to-large projects:</p>
<p><strong>1. Easier Dependency Tracking.</strong><br /> &nbsp;&nbsp;&nbsp; When using variables, constants, or even JOINing to tables, we're never sure which lookup values are actually used. The removal of a row from the ShippingMethod table won't cause any compile errors in our code and will only present a problem when a query is actually executed. We may or may not even notice the problem. Using Pseudo-Constants gives us immediate visibility into dependencies:</p>
<div style="color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px; white-space: nowrap;"><span style="background: #ffffff; color: #0000ff;">CREATE&nbsp;</span><span style="background: #ffffff; color: #0000ff;">PROCEDURE</span><span style="background: #ffffff; color: #000000;"> Get_OvernightShippingOrders</span><br /> <span style="background: #ffffff; color: #0000ff;">AS</span><br /> <span style="background: #ffffff; color: #0000ff;">SELECT</span><span style="background: #ffffff; color: #000000;"> h</span><span style="background: #ffffff; color: #808080;">.*&nbsp;</span><span style="background: #ffffff; color: #0000ff;">FROM</span><span style="background: #ffffff; color: #000000;"> Sales</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">SalesOrderHeader h </span><br /> <span style="background: #ffffff; color: #808080;">JOIN</span><span style="background: #ffffff; color: #000000;"> ShipMethod</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">ShipMethodID const </span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span style="background: #ffffff; color: #0000ff;">ON</span><span style="background: #ffffff; color: #000000;"> h</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">ShipMethodID </span><span style="background: #ffffff; color: #808080;">=</span><span style="background: #ffffff; color: #000000;"> const</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">[OVERNIGHT J-FAST]</span><br /> <span style="background: #ffffff; color: #0000ff;">GO</span><br /> <span style="background: #ffffff; color: #008000;">-- View all objects that use this ShipMethod constants:</span><br /> <span style="background: #ffffff; color: #0000ff;">SELECT&nbsp;</span><span style="background: #ffffff; color: #ff00ff;">OBJECT_NAME</span><span style="background: #ffffff; color: #808080;">(</span><span style="background: #ffffff; color: #000000;">dep</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #ff00ff;">object_id</span><span style="background: #ffffff; color: #808080;">)&nbsp;</span><span style="background: #ffffff; color: #0000ff;">AS</span><span style="background: #ffffff; color: #000000;"> ReferencingObject</span><span style="background: #ffffff; color: #808080;">,</span><span style="background: #ffffff; color: #000000;"> c</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">name </span><span style="background: #ffffff; color: #0000ff;">AS</span><span style="background: #ffffff; color: #000000;"> ReferencedColumnName</span><br /> <span style="background: #ffffff; color: #0000ff;">FROM&nbsp;</span><span style="background: #ffffff; color: #008000;">sys</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #008000;">sql_dependencies</span><span style="background: #ffffff; color: #000000;"> dep</span><br /> <span style="background: #ffffff; color: #808080;">JOIN&nbsp;</span><span style="background: #ffffff; color: #008000;">sys</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #008000;">columns</span><span style="background: #ffffff; color: #000000;"> c </span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span style="background: #ffffff; color: #0000ff;">ON</span><span style="background: #ffffff; color: #000000;"> dep</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">referenced_major_id </span><span style="background: #ffffff; color: #808080;">=</span><span style="background: #ffffff; color: #000000;"> c</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #ff00ff;">object_id</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span style="background: #ffffff; color: #808080;">AND</span><span style="background: #ffffff; color: #000000;"> dep</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">referenced_minor_id </span><span style="background: #ffffff; color: #808080;">=</span><span style="background: #ffffff; color: #000000;"> c</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">column_id</span><br /> <span style="background: #ffffff; color: #0000ff;">WHERE</span><span style="background: #ffffff; color: #000000;"> dep</span><span style="background: #ffffff; color: #808080;">.</span><span style="background: #ffffff; color: #000000;">referenced_major_id </span><span style="background: #ffffff; color: #808080;">=&nbsp;</span><span style="background: #ffffff; color: #ff00ff;">OBJECT_ID</span><span style="background: #ffffff; color: #808080;">(</span><span style="background: #ffffff; color: #ff0000;">'ShipMethod.ShipMethodID'</span><span style="background: #ffffff; color: #808080;">)</span></div>
</div>
<p>&nbsp;</p>
<table border="1">
<tbody>
<tr><th>ReferencingObject</th><th>ReferencedColumnName</th></tr>
<tr>
<td>Get_OvernightShippingOrders</td>
<td>OVERNIGHT J-FAST</td>
</tr>
</tbody>
</table>
<p><strong>2. Easier Code Refactoring.</strong></p>
<p style="padding-left: 30px;">When using a literal, updating an ID becomes a painful search-and-replace project. Changing every stored procedure that used "ShipMethodID = 4" to a new value like, "ShipMethodID = 6" requires a manual review of the code to look for these hard-coded values. In a large enough project, you'll never be sure you got them.<br />If you're using Pseudo-Constants, it's a simple process of querying the dependencies (as outlined aboce) or altering the underlying view to provide a new literal value.</p>
<p><strong>3. The right data type every time.</strong></p>
<p style="padding-left: 30px;">From my own experience of seeing unexpected implicit data conversions, I know our literals and variables can sometimes use the wrong data type. This results in undetected performance hits when the SQL engine has to convert every row in the table to match the data type of your parameter. The Pseudo-Constant ensures you're only setting the data type in one place.</p>
<p><strong>4. Instant Recompiles for data changes.</strong></p>
<p style="padding-left: 30px;">If the value of "OVERNIGHT J-FAST" changes, you're required to ALTER the view. This will result in all dependent objects to obtain a new plan for their next execution. While it's rarely valuable in this situation, it's extremely beneficial if you use Pseudo-Constants for date ranges.</p>
<h2><strong>Other Uses</strong></h2>
<p><strong>1. Working in date ranges</strong></p>
<p style="padding-left: 30px;">Another exciting use of Pseudo-Constants is when working with date ranges. Pseudo-Constants can be used to supplement variables in returning a more selective dataset. I'll expand on this in a future post but imagine a query where the Psedo-Constant narrowed down your potential rows by 90% while the variable was used to get the exact range. This is far beneficial than a plan that returns all of your rows to be filtered at runtime.</p>
<h2>&nbsp;In closing</h2>
<p><span><strong>Disclaimer and a heartfelt thanks</strong>: Whenever possible, I will endeavor to give credit to people that provided a solution, idea, or inspiration for my own blog posts. These posts would not have possible without all the amazing people in the SQL Server community sharing their own solutions. While I'm not aware of anybody using this solution, I don't claim to be the first person to have thought of it. If there are any other sources for anything I cover, please contact me so that I may give proper attribution.</span></p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/10/44/56/83/Pseudo-Constant%20Demo.sql" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-10-44-56-83/Pseudo_2D00_Constant-Demo.sql">Pseudo-Constant Demo.sql</a></p>]]></content:encoded>
    </item>
    <item>
      <title>SQLCMD and PowerShell: Generate 450 Million Names With 20 Lines of Code</title>
      <link>https://docs.microsoft.com/archive/blogs/sql_server_appendix_z/sqlcmd-and-powershell-generate-450-million-names-with-20-lines-of-code</link>
      <pubDate>Sun, 03 Mar 2013 19:00:00 GMT</pubDate>
      <dc:creator><![CDATA[Jared Ko]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sql_server_appendix_z/2013/03/03/sqlcmd-and-powershell-generate-450-million-names-with-20-lines-of-code/</guid>
      <description><![CDATA[(It's actually 487,861,706 names but it didn't seem like a good title). Skip to the solution.
Note...]]></description>
      <content:encoded><![CDATA[<p>(It's actually 487,861,706 names but it didn't seem like a good title). <a href="#Solution">Skip to the solution</a>.</p>
<p><strong>Note on file sizes</strong>: As a full of this sample run require 25GB of disk space, I've placed a simple restriction in the sample code. Prior to running the code without the restriction, readers should be familiar with TempDB file size settings and be aware of how much space they normally require.</p>
<h2>Say Goodbye to large data scripts</h2>
<p>Who could ever find those big data files with a forgotten name sitting in a forgotten folder on a forgotten server, protected by permissions that nobody has? We wanted to forget them but coming up with large, non-repeating data scripts can be a lot of work. Fortunately our friends at the U.S. Census Bureau <a href="http://www.census.gov/main/www/access.html" target="_blank">love sharing data</a>.</p>
<p>One of the Census Bureau's publications is a list of <a href="http://www.census.gov/genealogy/www/data/1990surnames/names_files.html" target="_blank">frequently occuring first names and surnames</a>. Today, we'll download these data files and insert them into a table using nothing more than SQL Server Management Studio in SQLCMD mode.</p>
<p>The data we're using an aggregate of 1990 U.S. Census data. The full detail of the files, data format, and sampling methodology are available <a href="http://www.census.gov/genealogy/www/data/1990surnames/nam_meth.txt" target="_blank">here</a>. For our purposes, all we need to know is that it is a fixed-width data ASCII file and the "Name" column the first 15 characters of each line.</p>
<p>The files themselves have the following statistics:</p>
<table class="auto-style1">
<tbody>
<tr>
<td><strong>Name/URL</strong></td>
<td><strong>Description</strong></td>
<td><strong>File Size</strong></td>
<td><strong>Count of Unique Names</strong></td>
</tr>
<tr>
<td><a href="http://www.census.gov/genealogy/www/data/1990surnames/dist.all.last" target="_blank">dist.all.last</a></td>
<td>Last Names</td>
<td>2mb</td>
<td>88,799</td>
</tr>
<tr>
<td><a href="http://www.census.gov/genealogy/www/data/1990surnames/dist.female.first" target="_blank">dist.female.first</a></td>
<td>Female First names</td>
<td>146kb</td>
<td>4,275</td>
</tr>
<tr>
<td><a href="http://www.census.gov/genealogy/www/data/1990surnames/dist.male.first" target="_blank">dist.male.first</a></td>
<td>Male First Names</td>
<td>41kb</td>
<td>1,219</td>
</tr>
</tbody>
</table>
<p>The file itself looks like this:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/04/1050.dist.all.last.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-04/1050.dist.all.last.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/04/1050.dist.all.last.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-04/1050.dist.all.last.png" alt="" width="335" height="149" border="0" /></a></p>
<h2>PowerShell 2.0 Script</h2>
<p>We'll start out by testing the smallest data file, <em>dist.male.first</em>. We need a way to download this through PowerShell and <a href="http://learn-powershell.net/author/boeprox/" target="_blank">Boe Brox</a> has a blog <a href="http://learn-powershell.net/2011/02/11/using-powershell-to-query-web-site-information/" target="_blank">post that shows us how</a>. In his article, we see that the <a href="http://msdn.microsoft.com/en-us/library/system.net.webclient.aspx" target="_blank">Net.WebClient</a> class provides our needed functionality. We'll run our first test by downloading a file and looking at the first 200 characters:</p>
<pre class="scroll" style="margin: 30px; font-family: 'Lucida Console'; font-size: small;"><span style="color: orangered; background: white;">$URI</span><span style="color: #979797; background: white;">=</span><span style="color: darkred; background: white;">"</span><a href="http://www.census.gov/genealogy/www/data/1990surnames/dist.male.first" target="_blank"><span style="color: darkred; background: white;">http://www.census.gov/genealogy/www/data/1990surnames/dist.male.first</span></a><span style="color: darkred; background: white;">"</span>
<span style="color: orangered; background: white;">$web</span><span style="color: #979797; background: white;">=</span><span style="color: blue; background: white;">New-Object</span><span style="color: blueviolet; background: white;"> Net.WebClient</span>
<span style="color: orangered; background: white;">$result</span><span style="color: #979797; background: white;">=</span><span style="color: orangered; background: white;">$web</span><span style="color: #979797; background: white;">.</span><span style="background: white;">DownloadString(</span><span style="color: orangered; background: white;">$URI</span><span style="background: white;">)</span>
<span style="color: orangered; background: white;">$result</span><span style="color: #979797; background: white;">.</span><span style="background: white;">Substring(</span><span style="color: purple; background: white;">0</span><span style="color: #979797; background: white;">,</span><span style="color: purple; background: white;">200</span><span style="background: white;">)</span>
</pre>
<p>In the results, we see that individual names are the only entries using letters. Additionally, there are no hyphenated names, apostrophes, or any other special characters in the name. This makes parsing very easy.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/04/8461.PSOutputNames.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-04/8461.PSOutputNames.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/04/8461.PSOutputNames.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/257x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-04/8461.PSOutputNames.png" alt="" border="0" /></a></p>
<p>Having downloaded and viewed the file, we'll write a multi-line script in PowerShell, re-write it as a single-line script, then convert it to run in SQLCMD.</p>
<p>For multi-line, we will:</p>
<ol>
<li>Remove any characters that are not alphabetical or CR/LF, leaving only names on each line.</li>
<li>Split each line into an array element; wrap the line in quotes/parenthesis. I.E. <em>JAMES</em> becomes <em>,('JAMES')</em></li>
<li>Generate an INSERT statement on every 100th line.</li>
<li>Test the results.</li>
</ol>
<pre class="scroll" style="margin: 30px; font-family: 'Lucida Console'; font-size: small;"><span style="color: orangered; background: white;">$URI</span><span style="color: #979797; background: white;">=</span><span style="color: darkred; background: white;">"</span><a href="http://www.census.gov/genealogy/www/data/1990surnames/dist.male.first" target="_blank"><span style="color: darkred; background: white;">http://www.census.gov/genealogy/www/data/1990surnames/dist.male.first</span></a><span style="color: darkred; background: white;">"</span>
<span style="color: orangered; background: white;">$web</span><span style="color: #979797; background: white;">=</span><span style="color: blue; background: white;">New-Object </span><span style="color: blueviolet; background: white;">Net.WebClient</span>
<span style="color: orangered; background: white;">$webResult</span><span style="color: #979797; background: white;">=</span><span style="color: orangered; background: white;">$web</span><span style="color: #979797; background: white;">.</span><span style="background: white;">DownloadString(</span><span style="color: orangered; background: white;">$URI</span><span style="background: white;">)</span>
<span style="color: darkgreen; background: white;"># Using RegEx (Regular Expressions), eliminate anything that isn't Alpha or CRLF.</span>
<span style="color: orangered; background: white;">$webResult</span><span style="color: #979797; background: white;">=</span><span style="color: orangered; background: white;">$webResult </span><span style="color: #979797; background: white;">-replace</span><span style="color: darkred; background: white;"> '[^a-z\r\n]'</span><span style="color: #979797; background: white;">,</span>''
<span style="color: darkgreen; background: white;"># Remove Blank Lines.</span>
<span style="color: orangered; background: white;">$webResult</span><span style="color: #979797; background: white;">=</span><span style="color: orangered; background: white;">$webResult</span><span style="color: #979797; background: white;"> -replace</span> '<span style="color: darkred; background: white;">\r\n[^a-z]'</span><span style="color: #979797; background: white;">,</span>''
<span style="color: darkgreen; background: white;"># Split each line into an array</span>
<span style="color: orangered; background: white;">$names</span><span style="color: #979797; background: white;">=</span><span style="color: orangered; background: white;">$webResult</span><span style="color: #979797; background: white;">.</span><span style="background: white;">Split(</span><span style="color: darkred; background: white;">"`n`r"</span><span style="background: white;">)</span>
<span style="color: darkgreen; background: white;"># Remove the empty line at the end of the file</span>
<span style="color: orangered; background: white;">$names</span><span style="color: #979797; background: white;">=</span><span style="color: orangered; background: white;">$names</span><span style="color: #979797; background: white;"> |</span><span style="color: blue; background: white;"> Where-Object</span><span style="background: white;"> {</span><span style="color: orangered; background: white;">$_</span><span style="color: #979797; background: white;">.</span><span style="background: white;">length </span><span style="color: #979797; background: white;">-GT </span><span style="color: purple; background: white;">1</span><span style="background: white;">}</span>
<span style="color: orangered; background: white;">$lineCount</span><span style="color: #979797; background: white;">=</span><span style="color: purple; background: white;">0</span>
<span style="color: orangered; background: white;">$names</span><span style="color: #979797; background: white;">|</span><span style="color: blue; background: white;">ForEach-Object</span><span style="background: white;"> {</span>
<span style="color: darkgreen; background: white;"># Create a new batch every 100 lines</span>
<span style="background: white;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="color: darkblue; background: white;">if</span><span style="background: white;"> (</span><span style="color: orangered; background: white;">$lineCount</span><span style="color: #979797; background: white;">--</span><span style="color: #979797; background: white;"> -le </span><span style="color: purple; background: white;">0</span><span style="background: white;">) {</span>
<span style="background: white;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="color: darkred; background: white;">"GO`r`nINSERT #FirstName VALUES('</span><span style="color: orangered; background: white;">$_</span><span style="color: darkred; background: white;">')"</span>
<span style="background: white;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="color: orangered; background: white;">$lineCount</span><span style="color: #979797; background: white;">=</span><span style="color: purple; background: white;">100</span>
<span style="background: white;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span>
<span style="background: white;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="color: darkblue; background: white;">else</span>
<span style="background: white;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span><br />&nbsp;<span style="background: white;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="color: darkred; background: white;">",('</span><span style="color: orangered; background: white;">$_</span><span style="color: darkred; background: white;">')</span>"
<span style="background: white;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span>
<span style="color: #979797; background: white;"> <span style="background: white;">} </span>| </span><span style="color: blue; background: white;">Select-Object</span><span style="color: navy; background: white;"> -First </span><span style="color: purple; background: white;">10</span><span style="color: darkgreen; background: white;"> # Test by selecting the first 10 lines</span>
</pre>
<p>We should now have an output that looks like this:</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/04/8358.PSOutputSQL.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-04/8358.PSOutputSQL.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/04/8358.PSOutputSQL.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-04/8358.PSOutputSQL.png" alt="" width="255" height="149" border="0" /></a></p>
<p>Before we can put everything on one line, we want to take the additional step of removing unnecessary variables. This can be done through <a href="http://technet.microsoft.com/en-us/library/ee176927.aspx" target="_blank">piping</a> rather than storing results in a variable. We'll also shorten the variable names that we can't remove. Our code now looks like this:</p>
<pre class="scroll" style="margin: 30px; font-family: 'Lucida Console'; font-size: small;"><span style="color: orangered; background: white;">$URI</span><span style="color: #979797; background: white;">=</span><span style="color: darkred; background: white;">"</span><a href="http://www.census.gov/genealogy/www/data/1990surnames/dist.male.first" target="_blank"><span style="color: darkred; background: white;">http://www.census.gov/genealogy/www/data/1990surnames/dist.male.first</span></a><span style="color: darkred; background: white;">"</span>
<span style="color: orangered; background: white;">$lc</span><span style="color: #979797; background: white;">=</span><span style="color: purple; background: white;">0</span>
<span style="background: white;">((</span><span style="color: blue; background: white;">New-Object </span><span style="color: blueviolet; background: white;">Net.WebClient</span><span style="background: white;">)</span><span style="color: #979797; background: white;">.</span><span style="background: white;">DownloadString(</span><span style="color: orangered; background: white;">$URI</span><span style="background: white;">) </span><span style="color: #979797; background: white;">-replace</span>'<span style="color: darkred; background: white;">[^a-z\r\n]</span>'<span style="color: #979797; background: white;">,</span>''<span style="color: #979797; background: white;">-replace</span>'<span style="color: darkred; background: white;">\r\n[^a-z]</span>'<span style="color: #979797; background: white;">,</span>''<span style="background: white;">)</span><span style="color: #979797; background: white;">.</span><span style="background: white;">Split(</span><span style="color: darkred; background: white;">"`n`r"</span><span style="background: white;">) </span><span style="color: #979797; background: white;"><strong>|</strong></span>
<span style="background: white;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span></span><span style="color: blue; background: white;">Where-Object</span><span style="background: white;"> {</span><span style="color: orangered; background: white;">$_</span><span style="color: #979797; background: white;">.</span><span style="background: white;">length </span><span style="color: #979797; background: white;">-GT</span><span style="color: purple; background: white;">1</span><span style="background: white;">} </span><span style="color: #979797; background: white;">|</span><span style="color: blue; background: white;">ForEach-Object</span><span style="background: white;"> {</span>
<span style="background: white;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="color: darkblue; background: white;">if</span><span style="background: white;"> (</span><span style="color: orangered; background: white;">$lc</span><span style="color: #979797; background: white;">--</span><span style="color: #979797; background: white;">-le</span><span style="color: purple; background: white;">0</span><span style="background: white;">) {</span>
<span style="background: white;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="color: darkred; background: white;">"GO`r`nINSERT #FirstName VALUES('</span><span style="color: orangered; background: white;">$_</span><span style="color: darkred; background: white;">')"</span>
<span style="background: white;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="color: orangered; background: white;">$lc</span><span style="color: #979797; background: white;">=</span><span style="color: purple; background: white;">100</span>
<span style="background: white;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span>
<span style="background: white;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="color: darkblue; background: white;">else</span>
<span style="background: white;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span>
<span style="background: white;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="color: darkred; background: white;">",('</span><span style="color: orangered; background: white;">$_</span><span style="color: darkred; background: white;">')"</span>
<span style="background: white;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span>
<span style="background: white;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>} </span><span style="color: #979797; background: white;">|</span><span style="color: blue; background: white;">Select-Object </span><span style="color: navy; background: white;">-First</span><span style="color: purple; background: white;"> 10</span><span style="color: darkgreen; background: white;"> # Test by selecting the first 10 lines</span>
</pre>
<p>Finally, we remove all hope of readability by putting everything but the URI on one line like this:</p>
<pre class="scroll" style="margin: 30px; font-family: 'Lucida Console'; font-size: small;"><span style="color: orangered; background: white;">$URI</span><span style="color: #979797; background: white;">=</span><span style="color: darkred; background: white;">"</span><a href="http://www.census.gov/genealogy/www/data/1990surnames/dist.male.first" target="_blank"><span style="color: darkred; background: white;">http://www.census.gov/genealogy/www/data/1990surnames/dist.male.first</span></a><span style="color: darkred; background: white;">"</span><br /><span style="color: orangered; background: white;">$lc</span><span style="color: #979797; background: white;">=</span><span style="color: purple; background: white;">0</span><span style="background: white;">; ((</span><span style="color: blue; background: white;">New-Object </span><span style="color: blueviolet; background: white;">Net.WebClient</span><span style="background: white;">)</span><span style="color: #979797; background: white;">.</span><span style="background: white;">DownloadString(</span><span style="color: orangered; background: white;">$URI</span><span style="background: white;">) </span><span style="color: #979797; background: white;">-replace</span> '<span style="color: darkred; background: white;">[^a-z\r\n]'</span><span style="color: #979797; background: white;">,</span>'' <span style="color: #979797; background: white;">-replace</span><span style="color: darkred; background: white;"> '\r\n[^a-z]'</span><span style="color: #979797; background: white;">,'</span>'<span style="background: white;">)</span><span style="color: #979797; background: white;">.</span><span style="background: white;">Split(</span><span style="color: darkred; background: white;">"`n`r"</span><span style="background: white;">) </span><span style="color: #979797; background: white;">|</span><span style="color: blue; background: white;"> Where-Object</span><span style="background: white;"> {</span><span style="color: orangered; background: white;">$_</span><span style="color: #979797; background: white;">.</span><span style="background: white;">length </span><span style="color: #979797; background: white;">-GT</span> <span style="color: purple; background: white;">1</span><span style="background: white;">} </span><span style="color: #979797; background: white;">|</span><span style="color: blue; background: white;">ForEach-Object</span><span style="background: white;"> { </span><span style="color: darkblue; background: white;">if</span><span style="background: white;"> (</span><span style="color: orangered; background: white;">$lc</span><span style="color: #979797; background: white;"> -</span><span style="color: #979797; background: white;">le </span><span style="color: purple; background: white;">0</span><span style="background: white;">) { </span><span style="color: darkred; background: white;">"GO`r`nINSERT #FirstName VALUES('</span><span style="color: orangered; background: white;">$_</span><span style="color: darkred; background: white;">')"</span><span style="background: white;">; </span><span style="color: orangered; background: white;">$lc</span><span style="color: #979797; background: white;">=</span><span style="color: purple; background: white;">100</span><span style="background: white;"> } </span><span style="color: darkblue; background: white;">else</span><span style="background: white;"> { </span><span style="color: darkred; background: white;">",('</span><span style="color: orangered; background: white;">$_</span><span style="color: darkred; background: white;">')"</span><span style="background: white;"> } } </span><span style="color: #979797; background: white;">|</span><span style="color: blue; background: white;"> Select-Object </span><span style="color: navy; background: white;">-First </span><span style="color: purple; background: white;">10</span>
</pre>
<p>After testing the script one final time, we're ready to put it in SQLCMD.</p>
<h2>Porting to SQLCMD</h2>
<h3>One More PowerShell SQLCMD caveat:</h3>
<p>Adding quotes to your command can be a challenge. This is because SQLCMD and the Command Shell both attempt to strip quotes from strings. PowerShell often allows single quotes and double quotes interchangeably but it's not possible 100% of the time. With that, I (embarassingly) present the Quote variable:</p>
<p style="margin: 30px; font-family: 'Lucida Console'; font-size: small;"><span style="background: silver; mso-highlight: silver;">:setvar Q """"""""</span></p>
<p>This variable, while not pretty, will be inserted into each of the sections that require double-quotes.</p>
<h2><a name="Solution"></a>The Solution</h2>
<p>The final query is shown below.</p>
<p><strong>Reminder</strong>: As the full script results in a 25GB TempDB file, this script has been modified to return the first 20,000 rows. For demonstration purposes, a variable "SampleCount" limits the INSERT to 100 rows from each file (100 last * (100 first+100 first)). In addition to the 25GB disk requirement, running the full query on my system (a six-core desktop PC) took about 7 minutes. With that in mind, if you REALLY want to throttle your system to get all 487 million rows, simply comment out the second SETVAR command.</p>
<pre class="scroll" style="margin: 30px; font-family: 'Lucida Console'; font-size: small;"><span style="color: blue;">SET</span> <span style="color: blue;">NOCOUNT</span> <span style="color: blue;">ON</span>
<span style="background: silver; mso-highlight: silver;">:out $(TEMP)\Names.sql</span>
<span style="background: silver; mso-highlight: silver;">:setvar SampleCount ""</span>
<span style="background: silver; mso-highlight: silver;">:setvar SampleCount "| Select-Object -First 100"</span>
<span style="background: silver; mso-highlight: silver;">:setvar Q """"""""</span>
<span style="background: silver; mso-highlight: silver;">:setvar PSCmd "PowerShell -InputFormat none -Command"</span>
&nbsp;
<span style="background: silver; mso-highlight: silver;">:setvar URI "</span><a href="http://www.census.gov/genealogy/www/data/1990surnames/dist.all.last" target="_blank"><span style="background: silver; mso-highlight: silver;">http://www.census.gov/genealogy/www/data/1990surnames/dist.all.last</span></a><span style="background: silver; mso-highlight: silver;">"</span>
<span style="background: silver; mso-highlight: silver;">!!$(PSCmd) "&amp; { $lc = 0; ((New-Object Net.WebClient).DownloadString('$(URI)') -replace '[^a-z\r\n]','' -replace '\r\n[^a-z]','').Split($(Q)`n`r$(Q)) | Where-Object {$_.length -GT 1} | ForEach-Object { if ($lc-- -le 0) { $(Q)GO`r`nINSERT #LastNames<span style="mso-spacerun: yes;">&nbsp; </span>VALUES('$_')$(Q); $lc = 100 } else { $(Q),('$_')$(Q) } } $(SampleCount) }"</span>
<span style="background: silver; mso-highlight: silver;">:setvar URI "</span><a href="http://www.census.gov/genealogy/www/data/1990surnames/dist.female.first" target="_blank"><span style="background: silver; mso-highlight: silver;">http://www.census.gov/genealogy/www/data/1990surnames/dist.female.first</span></a><span style="background: silver; mso-highlight: silver;">"</span>
<span style="background: silver; mso-highlight: silver;">!!$(PSCmd) "&amp; { $lc = 0; ((New-Object Net.WebClient).DownloadString('$(URI)') -replace '[^a-z\r\n]','' -replace '\r\n[^a-z]','').Split($(Q)`n`r$(Q)) | Where-Object {$_.length -GT 1} | ForEach-Object { if ($lc-- -le 0) { $(Q)GO`r`nINSERT #FirstNames VALUES('$_')$(Q); $lc = 100 } else { $(Q),('$_')$(Q) } } $(SampleCount) }"</span>
<span style="background: silver; mso-highlight: silver;">:setvar URI "</span><a href="http://www.census.gov/genealogy/www/data/1990surnames/dist.male.first" target="_blank"><span style="background: silver; mso-highlight: silver;">http://www.census.gov/genealogy/www/data/1990surnames/dist.male.first</span></a><span style="background: silver; mso-highlight: silver;">"</span>
<span style="background: silver; mso-highlight: silver;">!!$(PSCmd) "&amp; { $lc = 0; ((New-Object Net.WebClient).DownloadString('$(URI)') -replace '[^a-z\r\n]','' -replace '\r\n[^a-z]','').Split($(Q)`n`r$(Q)) | Where-Object {$_.length -GT 1} | ForEach-Object { if ($lc-- -le 0) { $(Q)GO`r`nINSERT #FirstNames VALUES('$_')$(Q); $lc = 100 } else { $(Q),('$_')$(Q) } } $(SampleCount) }"</span>
&nbsp;
<span style="background: silver; mso-highlight: silver;">:out STDOUT</span>
<span style="color: blue;">IF</span> <span style="color: fuchsia;">OBJECT_ID</span><span style="color: gray;">(</span><span style="color: red;">'tempdb..#FullNames'</span><span style="color: gray;">)</span> <span style="color: gray;">IS</span> <span style="color: gray;">NOT</span> <span style="color: gray;">NULL</span>
<span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">DROP</span> <span style="color: blue;">TABLE</span> <span style="color: teal;">#FullNames</span>
<span style="color: blue;">IF</span> <span style="color: fuchsia;">OBJECT_ID</span><span style="color: gray;">(</span><span style="color: red;">'tempdb..#LastNames'</span><span style="color: gray;">)</span> <span style="color: gray;">IS</span> <span style="color: gray;">NULL</span>
<span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">CREATE</span> <span style="color: blue;">TABLE</span> <span style="color: teal;">#LastNames</span><span style="color: gray;">(</span><span style="color: teal;">LastName</span> <span style="color: blue;">VARCHAR</span><span style="color: gray;">(</span>30<span style="color: gray;">))</span>
<span style="color: blue;">IF</span> <span style="color: fuchsia;">OBJECT_ID</span><span style="color: gray;">(</span><span style="color: red;">'tempdb..#FirstNames'</span><span style="color: gray;">)</span> <span style="color: gray;">IS</span> <span style="color: gray;">NULL</span>
<span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">CREATE</span> <span style="color: blue;">TABLE</span> <span style="color: teal;">#FirstNames</span><span style="color: gray;">(</span><span style="color: teal;">FirstName</span> <span style="color: blue;">VARCHAR</span><span style="color: gray;">(</span>30<span style="color: gray;">))</span>
<span style="color: blue;">TRUNCATE</span> <span style="color: blue;">TABLE</span> <span style="color: teal;">#LastNames</span>
<span style="color: blue;">TRUNCATE</span> <span style="color: blue;">TABLE</span> <span style="color: teal;">#FirstNames</span>
GO
<span style="background: silver; mso-highlight: silver;">:r $(TEMP)\Names.sql</span>
<span style="color: blue;">SELECT</span> <span style="color: gray;">*</span> <span style="color: blue;">INTO</span> <span style="color: teal;">#FullNames</span> <span style="color: blue;">FROM</span> <span style="color: teal;">#LastNames</span> <span style="color: gray;">CROSS</span> <span style="color: gray;">JOIN</span> <span style="color: teal;">#FirstNames</span>
<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: teal;">NameCount</span> <span style="color: blue;">FROM</span> <span style="color: teal;">#FullNames</span>
</pre>
<p>For readability (seriously), I've added extra spaces between lines. If you want the promised "20 lines of code" from the title, you can actually get it down to 17 by removing extra spacing and concatenating all of your T-SQL (putting a semicolon between each command). You can get it to 15 lines by removing the SampleCount variables.</p>
<h2>Extending the Solution</h2>
<p>We took a lot of steps to reduce this to the bare-minimum data for the demo but the best data representation would actually have repeating names. If America has 314 million people, our table should have 104,810 people named James Smith (and 2.22 people named Jared Ko). This is all available from the other columns in these tables.</p>
<p>We could also add <a href="http://www.census.gov/population/age/data/2011comp.html" target="_blank">demographic information</a>, <a href="http://www.census.gov/hhes/www/income/" target="_blank">income ranges</a>, <a href="http://www2.census.gov/census_2010/03-Demographic_Profile/" target="_blank">give them all a place to live</a>, and if we're still not tired, start building our <a href="http://www.census.gov/population/international/data/idb/informationGateway.php" target="_blank">international database</a>.</p>
<h2>Additional Reading</h2>
<ul>
<li><a href="http://social.technet.microsoft.com/wiki/contents/articles/4310.powershell-working-with-regular-expressions-regex.aspx" target="_blank">PowerShell - Working With Regular Expressions (regex)</a></li>
<li><a href="http://blogs.technet.com/b/heyscriptingguy/archive/2008/01/17/how-can-i-use-windows-powershell-to-replace-characters-in-a-text-file.aspx" target="_blank">(Hey Scripting Guy) Use Windows PowerShell to Replace Characters in a Text File</a></li>
<li><a href="http://learn-powershell.net/2011/02/11/using-powershell-to-query-web-site-information/" target="_blank">Using PowerShell to Query Web Site Information</a></li>
<li><a href="http://technet.microsoft.com/en-us/library/ee176927.aspx" target="_blank">Piping and the pipeline</a></li>
</ul>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/10/39/86/02/GenerateNames.sql" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-10-39-86-02/GenerateNames.sql">GenerateNames.sql</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Hacking SQLCMD Mode: Introducing PowerShell</title>
      <link>https://docs.microsoft.com/archive/blogs/sql_server_appendix_z/hacking-sqlcmd-mode-introducing-powershell</link>
      <pubDate>Wed, 27 Feb 2013 20:30:00 GMT</pubDate>
      <dc:creator><![CDATA[Jared Ko]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sql_server_appendix_z/2013/02/27/hacking-sqlcmd-mode-introducing-powershell/</guid>
      <description><![CDATA[Disclaimer and a heartfelt thanks:&nbsp; Whenever possible, I will endeavor to give credit to people...]]></description>
      <content:encoded><![CDATA[<p><strong>Disclaimer and a heartfelt thanks:</strong>&nbsp; Whenever possible, I will endeavor to give credit to people that provided a solution, idea, or inspiration for my own blog posts. These posts would not have possible without all the amazing people in the SQL Server and PowerShell community sharing their own solutions. While I'm not aware of anybody using PowerShell in SQLCMD mode, I don't claim to be the first person to have thought of it. If there are any other sources for anything I cover, please contact me so that I may give proper attribution.</p>
<h2>Goodbye Command Shell. Hello PowerShell.</h2>
<p>It seems like the relationship between SQL Server and PowerShell is getting a lot of attention lately. Wayne Sheffield just ran a series titled, "<a title="A month of PowerShell" href="http://blogs.msdn.com/controlpanel/blogs/posteditor.aspx/blog.waynesheffield.com/wayne/a-month-of-powershell/" target="_blank">A month of PowerShell</a>" which covers just about everything you could want to know about SQL SMO and PowerShell. As I've started using PowerShell in early 2011, there's not much I can add to what Wayne's doing. So instead of using PowerShell to connect to SQL Server, we're going to use SQLCMD mode to talk to PowerShell.</p>
<p>This is new way of using SQLCMD that I'm really excited about. It's not part of any service pack but something that's been available to us for a very long time. It seems that we just failed to notice. Though PowerShell, we can start executing CmdLets, small pieces of code, and combine pieces of SQL Server with PowerShell to make everything a little bit easier.</p>
<h2>Running PowerShell from SQLCMD</h2>
<h3>First, an undocumented parameter</h3>
<p>An important thing to note (and <span style="color: #ff0000;">required for PowerShell 2.0 users</span>): When running PowerShell through SQLCMD, you should always include the following parameter:</p>
<p>&nbsp;<span style="color: #ff0000;">-InputFormat none</span></p>
<p>The problem is described <a title="here" href="http://connect.microsoft.com/PowerShell/feedback/details/572313/powershell-exe-can-hang-if-stdin-is-redirected">here</a> and, while PowerShell 3.0 behaves fine without this switch, I personally leave it in my scripts for backwards compatibility.</p>
<h3>Want BCP? Remember where your server is</h3>
<p>As I present these scripts, it's with the assumption that your client PC and your server are not the same machine. This means that I won't use BCP or other commands that assume your data is on the same computer as your server.</p>
<h3>The script-signing barrier</h3>
<p>Upon installation, PowerShell's default security level prohibits the execution of unsigned scripts. This is a very important feature and one that can easily be configured to an individual's needs. While changing this setting would make things easier, I like to find solutions that work "out of the box", without changes to system settings or additional software. Its with this goal in mind that I'm providing solutions that will execute without changing the default PowerShell security settings. There are easier and cleaner ways but (as far as I know) this is the only way to do it without extra steps.</p>
<h3>Let's form a nice, long line...</h3>
<p>The last thing to remember is that we're performing each PowerShell call in a single line with a semicolon ( <strong> ;</strong> ) between commands.While there are some tricks to improve readability, it still won't match up to the clean style you get from other code.</p>
<h2>Hello PowerShell World</h2>
<p>What script would be complete without the obligatory "Hello World"? All you have to do is make sure PowerShell is installed, turn on SQLCMD mode, and execute the following line:</p>
<p><span class="auto-style1" style="background: silver; mso-highlight: silver;">!! PowerShell -InputFormat none -Command "&amp; { Write-Output 'Hello PowerShell World!' }"</span></p>
<p>If everything went well, you'll see an output similar to this:</p>
<p>&nbsp;<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/04/2705.HelloWorld.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-04/2705.HelloWorld.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/04/2705.HelloWorld.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-04/2705.HelloWorld.png" alt="" border="0" /></a></p>
<h2>Let's Make a Numbers Table</h2>
<p>Adam Mechanic has a post titled, <a href="http://sqlblog.com/blogs/adam_machanic/archive/2006/07/12/you-require-a-numbers-table.aspx" target="_blank">You REQUIRE a numbers table!</a> Adam took over 15 lines to write the SELECT part (probably because he had a choice) but we're going to do it in one line (because we don't have a choice). It's also going to be slower and less-legible than Adam's, but... well... We're doing it in PowerShell! That's got to count for something!</p>
<p><span class="auto-style1" style="color: green;">-- Execute CREATE TABLE from within our script</span><br /> <span class="auto-style1"><span style="background: silver; mso-highlight: silver;">:OUT $(TEMP)\Numbers.sql</span></span><br /> <span class="auto-style1"><span style="color: blue;">PRINT</span> <span style="color: red;">'</span></span><br /> <span class="auto-style1" style="color: red;">SET NOCOUNT ON</span><br /> <span class="auto-style1" style="color: red;">USE TempDB</span><br /> <span class="auto-style1" style="color: red;">GO</span><br /> <span class="auto-style1" style="color: red;">IF OBJECT_ID(''Numbers'') IS NULL CREATE TABLE Numbers (Number INT)</span><br /> <span class="auto-style1" style="color: red;">TRUNCATE TABLE TempDB..Numbers</span><br /> <span class="auto-style1" style="color: red;">GO</span><br /> <span class="auto-style1" style="color: red;">'</span><br /> <span class="auto-style1" style="color: green;">-- If you forget the GO statement, the lower code executes first.</span><br /> <span class="auto-style1" style="color: blue;">GO</span><br /> <span class="auto-style1"><span style="background: silver; mso-highlight: silver;">!! PowerShell -InputFormat none -Command "&amp; { (1..1000) | ForEach-Object {Write-Output ('INSERT Numbers VALUES (' + $_ + ')' )} }"</span></span><br /> <span class="auto-style1" style="color: green;">-- Redirect output to the message pane</span><br /> <span class="auto-style1"><span style="background: silver; mso-highlight: silver;">:OUT STDOUT</span></span><br /> <span class="auto-style1" style="color: green;">-- Execute our newly-created script.</span><br /> <span class="auto-style1"><span style="background: silver; mso-highlight: silver;">:r $(TEMP)\Numbers.sql</span></span><br /> <span class="auto-style1" style="color: green;">-- Check for our numbers table</span><br /> <span class="auto-style1"> <span style="color: blue;">SELECT</span> <span style="color: gray;">*</span> <span style="color: blue;">FROM</span> <span style="color: teal;">tempdb</span> <span style="color: gray;">..</span><span style="color: teal;">Numbers</span></span></p>
<p>After executing the above code, you should see results that look similar to this:</p>
<p>&nbsp;<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/04/3823.numbers.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-04/3823.numbers.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/04/3823.numbers.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-04/3823.numbers.png" alt="" width="150" height="133" border="0" /></a></p>
<p>Note that the results won't show up in grid mode (even if you've chosen "Results to Grid"), but will be present in the "Messages" tab instead. This is a result of redirecting output to STDOUT.</p>
<h2>SQLCMD variables for script block reuse</h2>
<p>Finally, let's make it even easier to run our code. Nobody wants to risk a typo or waste screen real-estate when these PowerShell scripts start getting really long.</p>
<p class="auto-style1"><span style="background: silver; mso-highlight: silver;">!! PowerShell -InputFormat none -Command "&amp; { Write-Output 'Out with the old.' }"</span><br /><br /> <span style="background: silver; mso-highlight: silver;">:setvar PSCmd "PowerShell -InputFormat none -Command"</span><br /><br /> <span style="background: silver; mso-highlight: silver;">!!$(PSCmd) "&amp; { Write-Output 'In with the new!' }"</span><br /> <span style="background: silver; mso-highlight: silver;">!!$(PSCmd) "&amp; { Write-Output 'This is a little easier to read.' }"</span></p>
<h2>Next up: Say Hello to 450 million of your closest friends.</h2>
<p>In the next post, I'll provide you with a 20-line script to generate a table of 450 million unique names. Following that, I'll take a break from SQLCMD and PowerShell to introduce something new (or new to me) on the SQL Server performance side.</p>]]></content:encoded>
    </item>
    <item>
      <title>SQL Server Management Studio: Hacking SQLCMD Mode</title>
      <link>https://docs.microsoft.com/archive/blogs/sql_server_appendix_z/sql-server-management-studio-hacking-sqlcmd-mode</link>
      <pubDate>Sat, 23 Feb 2013 22:57:00 GMT</pubDate>
      <dc:creator><![CDATA[Jared Ko]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sql_server_appendix_z/2013/02/23/sql-server-management-studio-hacking-sqlcmd-mode/</guid>
      <description><![CDATA[Notice: This article is geared toward people already familiar with SQLCMD mode in SQL Server...]]></description>
      <content:encoded><![CDATA[<p><strong>Notice: This article is geared toward people already familiar with SQLCMD mode in SQL Server Management Studio. </strong>Though not extremely advanced, readers should understand <a title="documented functionality" href="http://msdn.microsoft.com/en-us/library/ms174187.aspx" target="_blank">documented functionality</a> of SQLCMD first. A basic understanding of DOS Command Shell will also provide the best results from trying these examples.<strong><br /></strong></p>
<p>The steps outlined in this article deal with executing dynamically-generated files. Though we are creating and running our own files in the same script, the results are less-predictable as complexity increases.<strong> Whenever trying sample code (from anywhere), you should execute in an environment that can tolerate accidental loss. <br /></strong></p>
<h2>Not SQLCMD I Already Tried It...</h2>
<p>If you're like me, you've probably spent the last several years in and out of SQL Server Management Studio's SQLCMD mode. It's got some great functionality but activating it came with the cost of disabling IntelliSense. Personally, I've always ended up turning it off and forgetting it for several months... Until Now...</p>
<p>Over the next several posts, I'm going to cover all the issues that made you give up on SQLCMD mode in the past. My goal isn't to make you keep that button active in SSMS, but to make you consider it as the productivity enhancer you'll never forget again.</p>
<p>This post begins with workaround for minor annoyances like the inability to program variables. The second post will quickly move out of command shell basics and provide background for the third post, where the fun really begins. In the third post I'll show you how to write 20 lines of code to create a sample "people" table with 450 million unique names.</p>
<p>Oh yeah... I don't have a solution for using IntelliSense with SQLCMD mode but it'll still be worth it....</p>
<h2>But I Can't Programmatically Set My Variables</h2>
<p>SQLCMD mode allows you to set variables based on literal values. Unfortunately you can't set variables based on the output of SQL Server. It's also not possible through concatenation of other SQLCMD variables or with environment variables.</p>
<p><span style="color: #ff0000;">(This is not supported)</span></p>
<pre style="padding-left: 30px; margin: 0in; font-family: Consolas; font-size: 9.5pt;"><span style="margin: 0in; font-family: Consolas; font-size: 9.5pt; background: silver; mso-highlight: silver;">:SETVAR FileName (SELECT @@Servername + '.txt')</span>

<span style="margin: 0in; font-family: Consolas; font-size: 9.5pt; background: silver; mso-highlight: silver;">:SETVAR NewVar $(OldVar1)$(OldVar2)</span>

</pre>
<p><span style="color: #ff0000;">(This is not supported)</span></p>
<p>While we can't use the syntax above, we can still get the desired results by generating the script in a second file.</p>
<h3>Programmatically Generating a "Variables File"</h3>
<pre style="padding-left: 30px;"><code class="mysql"><span style="font-family: arial,helvetica,sans-serif;">The following script generates a file called "GetServerName.sql" in the system temp folder. The file contents, a SETVAR command, will then be read from the same script. <br /><br />After executing "GetServerName", we'll use our new variable $(Filepath) to create a test file of system users (server_principals).<br /><br />Just for fun, we'll also open both files in to review them Notepad at the end.</span> <span style="font-family: arial,helvetica,sans-serif;"><span style="color: #ff0000;">Remember to close Notepad</span> because SQLCMD is patiently waiting and won't continue until you do.</span><br /></code></pre>
<pre style="padding-left: 30px; margin: 0in; font-family: Consolas; font-size: 9.5pt;"><span style="background: silver; mso-highlight: silver;">:OUT $(TEMP)\GetServerName.sql</span>
<span style="color: blue;">PRINT</span> <span style="color: red;">':SETVAR FilePath $(TEMP)\'</span> <span style="color: gray;">+</span> <span style="color: fuchsia;">@@SERVERNAME</span> <span style="color: gray;">+</span> <span style="color: red;">'.txt'</span>
<span style="margin: 0in; font-family: Consolas; font-size: 9.5pt; color: blue;">GO</span>
<span style="background: silver; mso-highlight: silver;">:OUT stdout</span>
<span style="background: silver; mso-highlight: silver;">:r $(TEMP)\GetServerName.sql</span>
<span style="margin: 0in; font-family: Consolas; font-size: 9.5pt; color: blue;">GO</span>
<span style="background: silver; mso-highlight: silver;">:OUT $(FilePath)</span>
<span style="color: blue;">SELECT</span> <span style="color: teal;">name</span><span style="color: gray;">,</span> <span style="color: teal;">create_date</span> 
<span style="color: blue;">FROM</span> <span style="color: blue;">master</span><span style="color: gray;">.</span><span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">server_principals</span>
<span style="margin: 0in; font-family: Consolas; font-size: 9.5pt; color: blue;">GO</span>
<span style="background: silver; mso-highlight: silver;">:OUT stdout</span>
<span style="background: silver; mso-highlight: silver;">!!notepad $(TEMP)\GetServerName.sql</span>
<span style="background: silver; mso-highlight: silver;">!!notepad $(FilePath)</span></pre>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt;">&nbsp;</p>
<p><strong>Some important items to note:</strong></p>
<ul>
<li>Observe the file path when notepad opens the first file (GetServerName.sql). Notice that the system parameter, $(TEMP), has already resolved itself to the full path of the temp directory.</li>
<li>Be aware of the backslash character ( <strong>\</strong> ) preceding a variable as it behaves like an escape character, negating the $ of the next variable.</li>
</ul>
<h2>There's no conditional (If/Then) logic in SQLCMD</h2>
<p>True again! And how do we fix that? We're going to solve this one with another dynamically-generated file.</p>
<p>Suppose we wanted BULK IMPORT a local file from a drop folder, run BCP, or process a set of other SQLCMD functions. If our target files didn't exist, we'd normally have no way to exit the script. However, we can use DOS commands to perform similar actions to those in the previous example. We do this by generating a file that contains one of two scripts (based on a condition being met). We first create a "Fail/Exit" file. As we execute, we replace the file when we succeed.</p>
<pre style="padding-left: 30px; margin: 0in; font-family: Consolas; font-size: 9.5pt;"><span style="margin: 0in; font-family: Consolas; font-size: 9.5pt; color: green;">-- SQLCMD Error Handling</span>
<span style="background: silver; mso-highlight: silver;">:setvar ErrorCheckFile "ErrorCheckFile.sql"</span>
<span style="margin: 0in; font-family: Consolas; font-size: 9.5pt;">&nbsp;</span>
<span style="margin: 0in; font-family: Consolas; font-size: 9.5pt; color: green;">-- Set DOS commands that will display in the output window and run SQLCMD EXIT.</span>
<span style="background: silver; mso-highlight: silver;">:setvar ErrorStatusCommand "(ECHO !!ECHO ValidationFailure. Terminating Script. &amp;&amp; ECHO :Exit)"</span>
<span style="margin: 0in; font-family: Consolas; font-size: 9.5pt;">&nbsp;</span>
<span style="margin: 0in; font-family: Consolas; font-size: 9.5pt; color: green;">-- The following line creates the file. Use this line for each situation that might require us to stop.</span>
<span style="background: silver; mso-highlight: silver;">!! $(ErrorStatusCommand) &gt; $(TEMP)$(ErrorCheckFile)</span>
<span style="margin: 0in; font-family: Consolas; font-size: 9.5pt;">&nbsp;</span>
<span style="margin: 0in; font-family: Consolas; font-size: 9.5pt; color: green;">-- See if a file exists. If so, replace our EXIT command with a blank file.</span>
<span style="background: silver; mso-highlight: silver;">!! If EXIST $(TEMP)\*.* @ECHO. &gt; $(TEMP)$(ErrorCheckFile)</span>
<span style="margin: 0in; font-family: Consolas; font-size: 9.5pt;">&nbsp;</span>
<span style="margin: 0in; font-family: Consolas; font-size: 9.5pt; color: green;">-- Now read/execute the result</span>
<span style="background: silver; mso-highlight: silver;">:r $(TEMP)$(ErrorCheckFile)</span>
<span style="background: silver; mso-highlight: silver;">!! ECHO Found files in the Temp folder (this is normal).</span>
<span style="background: silver; mso-highlight: silver;">!! ECHO.</span>
<span style="background: silver; mso-highlight: silver;">!! ECHO Checking Next File.</span>
<span style="margin: 0in; font-family: Consolas; font-size: 9.5pt;">&nbsp;</span>
<span style="margin: 0in; font-family: Consolas; font-size: 9.5pt; color: green;">-- Reset the file back to Exit</span>
<span style="background: silver; mso-highlight: silver;">!! $(ErrorStatusCommand) &gt; $(TEMP)$(ErrorCheckFile)</span>
<span style="margin: 0in; font-family: Consolas; font-size: 9.5pt; color: green;">-- Try again with a file that shouldn't exist</span>
<span style="background: silver; mso-highlight: silver;">!! If EXIST $(TEMP)\ThisFileShouldNotBeHere.txt @ECHO. &gt; $(TEMP)$(ErrorCheckFile)</span>
<span style="margin: 0in; font-family: Consolas; font-size: 9.5pt;">&nbsp;</span>
<span style="margin: 0in; font-family: Consolas; font-size: 9.5pt; color: green;">-- Now read/execute the result</span>
<span style="background: silver; mso-highlight: silver;">:r $(TEMP)$(ErrorCheckFile)</span>
<span style="background: silver; mso-highlight: silver;">!! ECHO You should not see this.</span>
<span style="margin: 0in; font-family: Consolas; font-size: 9.5pt;"><span style="color: blue;">PRINT</span><span style="color: red;"> 'You should not see this either'</span></span>
</pre>
<p><span style="background-color: #ffffff;">If our script ran correctly, the output window will contain the following text:</span></p>
<p class="auto-style3" style="width: 722px;"><span class="auto-style2"><code><em>Found files in the Temp folder (this is normal).</em></code></span><code><em><br class="auto-style2" /><br class="auto-style2" /></em></code> <span class="auto-style2"><code><em>Checking Next File.</em></code></span><code><em><br class="auto-style2" /></em></code> <span class="auto-style2"><code><em>ValidationFailure. Terminating Script. </em></code></span><code> <br class="auto-style2" /></code></p>
<h2>Okay... Fancy DOS tricks... Is that it?</h2>
<p>Nope. This is where we start to have fun. We'll take it up a level in the next post but we needed to do the basics first. For now, I'll leave you with a way to perform loops.</p>
<p>This script executes itself in a loop. In order for it to work, you need to save it in the temp folder as "Loop.sql"&nbsp; (the quickest way to do that is to put <strong><em> <span style="color: #008000;">%TEMP%\Loop.sql</span></em></strong> in the Save-As box). Alternatively, you can update the script to reflect the file path of your choosing.</p>
<p style="padding-left: 60px;">&nbsp;<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/04/6661.filename.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-04/6661.filename.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/58/04/6661.filename.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-58-04/6661.filename.png" alt="" width="288" height="47" border="0" /></a></p>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt; padding-left: 30px;"><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: Consolas; font-size: 9.5pt; padding-left: 30px;"><span style="color: blue;">IF</span> <span style="color: fuchsia;">OBJECT_ID</span><span style="color: gray;">(</span><span style="color: red;">'tempdb..#state'</span><span style="color: gray;">)</span> <span style="color: gray;">IS</span> <span style="color: gray;">NULL</span></p>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt; color: blue; padding-left: 30px;">BEGIN</p>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt; padding-left: 30px;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">CREATE</span> <span style="color: blue;">TABLE</span> <span style="color: teal;">#state</span><span style="color: gray;">(</span><span style="color: teal;">TheStart</span> <span style="color: blue;">DATETIME2</span><span style="color: gray;">)</span></p>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt; padding-left: 30px;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">INSERT</span> <span style="color: teal;">#state</span> <span style="color: blue;">VALUES</span><span style="color: gray;">(</span><span style="color: fuchsia;">DATEADD</span><span style="color: gray;">(</span><span style="color: teal;">S</span><span style="color: gray;">,</span> 1<span style="color: gray;">,</span> <span style="color: fuchsia;">SYSDATETIME</span><span style="color: gray;">()))</span></p>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt; color: blue; padding-left: 30px;">END</p>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt; color: blue; padding-left: 30px;">GO</p>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt; padding-left: 30px;"><span style="color: blue;">PRINT</span> <span style="color: red;">'Beginning Loop1'</span></p>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt; color: blue; padding-left: 30px;">GO</p>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt; padding-left: 30px;"><span style="color: blue;">DECLARE</span> <span style="color: teal;">@TimeRemaining</span> <span style="color: blue;">INT</span></p>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt; padding-left: 30px;"><span style="color: blue;">SELECT</span> <span style="color: blue;">TOP</span> 1 <span style="color: teal;">@TimeRemaining</span> <span style="color: gray;">=</span> <span style="color: fuchsia;">DATEDIFF</span><span style="color: gray;">(</span><span style="color: teal;">MS</span><span style="color: gray;">,</span> <span style="color: fuchsia;">SYSDATETIME</span><span style="color: gray;">(),</span> <span style="color: teal;">TheStart</span><span style="color: gray;">)</span> <span style="color: blue;">FROM</span> <span style="color: teal;">#state</span></p>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt; padding-left: 30px;"><span style="color: blue;">PRINT</span> <span style="color: fuchsia;">CAST</span><span style="color: gray;">(</span><span style="color: teal;">@TimeRemaining</span> <span style="color: blue;">AS</span> <span style="color: blue;">VARCHAR</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">' milliseconds to go...'</span></p>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt; color: blue; padding-left: 30px;">GO</p>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt; padding-left: 30px;"><span style="background: silver; mso-highlight: silver;">:out $(TEMP)\loop2.sql</span></p>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt; padding-left: 30px;"><span style="color: blue;">IF</span> <span style="color: fuchsia;">SYSDATETIME</span><span style="color: gray;">()</span> <span style="color: gray;">&lt;=</span><span style="color: gray;">(</span><span style="color: blue;">SELECT</span> <span style="color: blue;">TOP</span> 1 <span style="color: teal;">TheStart</span> <span style="color: blue;">FROM</span> <span style="color: teal;">#state</span><span style="color: gray;">)</span></p>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt; color: blue; padding-left: 30px;">BEGIN</p>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt; padding-left: 30px;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">PRINT</span> <span style="color: red;">'PRINT ''Hello from loop2'''</span></p>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt; padding-left: 30px;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">PRINT</span> <span style="color: red;">':r $(TEMP)\loop.sql'</span></p>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt; color: blue; padding-left: 30px;">END</p>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt; color: blue; padding-left: 30px;">ELSE</p>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt; color: blue; padding-left: 30px;">BEGIN</p>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt; padding-left: 30px;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">PRINT</span> <span style="color: red;">'PRINT ''Last visit to Loop2!'''</span></p>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt; padding-left: 30px;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">PRINT</span> <span style="color: red;">'DROP TABLE #state'</span></p>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt; color: blue; padding-left: 30px;">END</p>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt; color: blue; padding-left: 30px;">GO</p>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt; padding-left: 30px;"><span style="background: silver; mso-highlight: silver;">:out STDOUT</span></p>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt; padding-left: 30px;"><span style="color: blue;">WAITFOR</span> <span style="color: blue;">DELAY</span> <span style="color: red;">'0:00:00.1'</span></p>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt; color: blue; padding-left: 30px;">GO</p>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt; padding-left: 30px;"><span style="color: blue;">PRINT</span> <span style="color: red;">'Running loop-checker...'</span></p>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt; color: blue; padding-left: 30px;">GO</p>
<p style="margin: 0in; font-family: Consolas; font-size: 9.5pt; padding-left: 30px;"><span style="background: silver; mso-highlight: silver;">:r $(TEMP)\loop2.sql</span></p>
<p>&nbsp;</p>
<h2 class="MsoNormal">&nbsp;A final note about debugging</h2>
<p>From my experience with SQLCMD Mode, the most-common causes of unexpected results were attributed to a missing GO statement or not inserting white space between lines.</p>
<ul>
<li>SQLCMD loves white space. If your command isn't working correctly, try adding a space above it... and below it...</li>
<li>SQLCMD also loves to parse everything and it won't want for the SQL Engine to return a response. If you need SQLCMD to work with an output from SQL Server, throw in a GO statement.</li>
<li>Remember not to put a backslash in front of a variable name. This does <strong>NOT</strong> work: $(TEMP)<strong>\</strong>$(FileName)</li>
<li>Add more vertical space. Add more GO statements.</li>
</ul>
<!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:View>Normal</w:View>
  <w:Zoom>0</w:Zoom>
  <w:TrackMoves/>
  <w:TrackFormatting/>
  <w:PunctuationKerning/>
  <w:ValidateAgainstSchemas/>
  <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
  <w:IgnoreMixedContent>false</w:IgnoreMixedContent>
  <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
  <w:DoNotPromoteQF/>
  <w:LidThemeOther>EN-US</w:LidThemeOther>
  <w:LidThemeAsian>JA</w:LidThemeAsian>
  <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
  <w:Compatibility>
   <w:BreakWrappedTables/>
   <w:SnapToGridInCell/>
   <w:WrapTextWithPunct/>
   <w:UseAsianBreakRules/>
   <w:DontGrowAutofit/>
   <w:SplitPgBreakAndParaMark/>
   <w:EnableOpenTypeKerning/>
   <w:DontFlipMirrorIndents/>
   <w:OverrideTableStyleHps/>
   <w:UseFELayout/>
  </w:Compatibility>
  <m:mathPr>
   <m:mathFont m:val="Cambria Math"/>
   <m:brkBin m:val="before"/>
   <m:brkBinSub m:val="&#45;-"/>
   <m:smallFrac m:val="off"/>
   <m:dispDef/>
   <m:lMargin m:val="0"/>
   <m:rMargin m:val="0"/>
   <m:defJc m:val="centerGroup"/>
   <m:wrapIndent m:val="1440"/>
   <m:intLim m:val="subSup"/>
   <m:naryLim m:val="undOvr"/>
  </m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="false"
  DefSemiHidden="false" DefQFormat="false" DefPriority="99"
  LatentStyleCount="371">
  <w:LsdException Locked="false" Priority="0" QFormat="true" Name="Normal"/>
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 1"/>
  <w:LsdException Locked="false" Priority="9" SemiHidden="true"
   UnhideWhenUsed="true" QFormat="true" Name="heading 2"/>
  <w:LsdException Locked="false" Priority="9" SemiHidden="true"
   UnhideWhenUsed="true" QFormat="true" Name="heading 3"/>
  <w:LsdException Locked="false" Priority="9" SemiHidden="true"
   UnhideWhenUsed="true" QFormat="true" Name="heading 4"/>
  <w:LsdException Locked="false" Priority="9" SemiHidden="true"
   UnhideWhenUsed="true" QFormat="true" Name="heading 5"/>
  <w:LsdException Locked="false" Priority="9" SemiHidden="true"
   UnhideWhenUsed="true" QFormat="true" Name="heading 6"/>
  <w:LsdException Locked="false" Priority="9" SemiHidden="true"
   UnhideWhenUsed="true" QFormat="true" Name="heading 7"/>
  <w:LsdException Locked="false" Priority="9" SemiHidden="true"
   UnhideWhenUsed="true" QFormat="true" Name="heading 8"/>
  <w:LsdException Locked="false" Priority="9" SemiHidden="true"
   UnhideWhenUsed="true" QFormat="true" Name="heading 9"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="index 1"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="index 2"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="index 3"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="index 4"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="index 5"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="index 6"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="index 7"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="index 8"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="index 9"/>
  <w:LsdException Locked="false" Priority="39" SemiHidden="true"
   UnhideWhenUsed="true" Name="toc 1"/>
  <w:LsdException Locked="false" Priority="39" SemiHidden="true"
   UnhideWhenUsed="true" Name="toc 2"/>
  <w:LsdException Locked="false" Priority="39" SemiHidden="true"
   UnhideWhenUsed="true" Name="toc 3"/>
  <w:LsdException Locked="false" Priority="39" SemiHidden="true"
   UnhideWhenUsed="true" Name="toc 4"/>
  <w:LsdException Locked="false" Priority="39" SemiHidden="true"
   UnhideWhenUsed="true" Name="toc 5"/>
  <w:LsdException Locked="false" Priority="39" SemiHidden="true"
   UnhideWhenUsed="true" Name="toc 6"/>
  <w:LsdException Locked="false" Priority="39" SemiHidden="true"
   UnhideWhenUsed="true" Name="toc 7"/>
  <w:LsdException Locked="false" Priority="39" SemiHidden="true"
   UnhideWhenUsed="true" Name="toc 8"/>
  <w:LsdException Locked="false" Priority="39" SemiHidden="true"
   UnhideWhenUsed="true" Name="toc 9"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Normal Indent"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="footnote text"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="annotation text"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="header"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="footer"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="index heading"/>
  <w:LsdException Locked="false" Priority="35" SemiHidden="true"
   UnhideWhenUsed="true" QFormat="true" Name="caption"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="table of figures"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="envelope address"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="envelope return"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="footnote reference"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="annotation reference"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="line number"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="page number"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="endnote reference"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="endnote text"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="table of authorities"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="macro"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="toa heading"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="List"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="List Bullet"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="List Number"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="List 2"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="List 3"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="List 4"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="List 5"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="List Bullet 2"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="List Bullet 3"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="List Bullet 4"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="List Bullet 5"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="List Number 2"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="List Number 3"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="List Number 4"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="List Number 5"/>
  <w:LsdException Locked="false" Priority="10" QFormat="true" Name="Title"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Closing"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Signature"/>
  <w:LsdException Locked="false" Priority="1" SemiHidden="true"
   UnhideWhenUsed="true" Name="Default Paragraph Font"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Body Text"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Body Text Indent"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="List Continue"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="List Continue 2"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="List Continue 3"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="List Continue 4"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="List Continue 5"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Message Header"/>
  <w:LsdException Locked="false" Priority="11" QFormat="true" Name="Subtitle"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Salutation"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Date"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Body Text First Indent"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Body Text First Indent 2"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Note Heading"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Body Text 2"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Body Text 3"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Body Text Indent 2"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Body Text Indent 3"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Block Text"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Hyperlink"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="FollowedHyperlink"/>
  <w:LsdException Locked="false" Priority="22" QFormat="true" Name="Strong"/>
  <w:LsdException Locked="false" Priority="20" QFormat="true" Name="Emphasis"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Document Map"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Plain Text"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="E-mail Signature"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="HTML Top of Form"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="HTML Bottom of Form"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Normal (Web)"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="HTML Acronym"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="HTML Address"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="HTML Cite"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="HTML Code"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="HTML Definition"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="HTML Keyboard"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="HTML Preformatted"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="HTML Sample"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="HTML Typewriter"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="HTML Variable"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Normal Table"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="annotation subject"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="No List"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Outline List 1"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Outline List 2"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Outline List 3"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Simple 1"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Simple 2"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Simple 3"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Classic 1"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Classic 2"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Classic 3"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Classic 4"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Colorful 1"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Colorful 2"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Colorful 3"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Columns 1"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Columns 2"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Columns 3"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Columns 4"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Columns 5"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Grid 1"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Grid 2"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Grid 3"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Grid 4"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Grid 5"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Grid 6"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Grid 7"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Grid 8"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table List 1"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table List 2"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table List 3"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table List 4"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table List 5"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table List 6"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table List 7"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table List 8"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table 3D effects 1"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table 3D effects 2"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table 3D effects 3"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Contemporary"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Elegant"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Professional"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Subtle 1"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Subtle 2"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Web 1"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Web 2"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Web 3"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Balloon Text"/>
  <w:LsdException Locked="false" Priority="39" Name="Table Grid"/>
  <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
   Name="Table Theme"/>
  <w:LsdException Locked="false" SemiHidden="true" Name="Placeholder Text"/>
  <w:LsdException Locked="false" Priority="1" QFormat="true" Name="No Spacing"/>
  <w:LsdException Locked="false" Priority="60" Name="Light Shading"/>
  <w:LsdException Locked="false" Priority="61" Name="Light List"/>
  <w:LsdException Locked="false" Priority="62" Name="Light Grid"/>
  <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1"/>
  <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2"/>
  <w:LsdException Locked="false" Priority="65" Name="Medium List 1"/>
  <w:LsdException Locked="false" Priority="66" Name="Medium List 2"/>
  <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1"/>
  <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2"/>
  <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3"/>
  <w:LsdException Locked="false" Priority="70" Name="Dark List"/>
  <w:LsdException Locked="false" Priority="71" Name="Colorful Shading"/>
  <w:LsdException Locked="false" Priority="72" Name="Colorful List"/>
  <w:LsdException Locked="false" Priority="73" Name="Colorful Grid"/>
  <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 1"/>
  <w:LsdException Locked="false" Priority="61" Name="Light List Accent 1"/>
  <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 1"/>
  <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 1"/>
  <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 1"/>
  <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 1"/>
  <w:LsdException Locked="false" SemiHidden="true" Name="Revision"/>
  <w:LsdException Locked="false" Priority="34" QFormat="true"
   Name="List Paragraph"/>
  <w:LsdException Locked="false" Priority="29" QFormat="true" Name="Quote"/>
  <w:LsdException Locked="false" Priority="30" QFormat="true"
   Name="Intense Quote"/>
  <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 1"/>
  <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 1"/>
  <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 1"/>
  <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 1"/>
  <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 1"/>
  <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 1"/>
  <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 1"/>
  <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 1"/>
  <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 2"/>
  <w:LsdException Locked="false" Priority="61" Name="Light List Accent 2"/>
  <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 2"/>
  <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 2"/>
  <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 2"/>
  <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 2"/>
  <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 2"/>
  <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 2"/>
  <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 2"/>
  <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 2"/>
  <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 2"/>
  <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 2"/>
  <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 2"/>
  <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 2"/>
  <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 3"/>
  <w:LsdException Locked="false" Priority="61" Name="Light List Accent 3"/>
  <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 3"/>
  <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 3"/>
  <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 3"/>
  <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 3"/>
  <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 3"/>
  <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 3"/>
  <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 3"/>
  <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 3"/>
  <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 3"/>
  <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 3"/>
  <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 3"/>
  <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 3"/>
  <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 4"/>
  <w:LsdException Locked="false" Priority="61" Name="Light List Accent 4"/>
  <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 4"/>
  <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 4"/>
  <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 4"/>
  <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 4"/>
  <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 4"/>
  <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 4"/>
  <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 4"/>
  <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 4"/>
  <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 4"/>
  <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 4"/>
  <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 4"/>
  <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 4"/>
  <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 5"/>
  <w:LsdException Locked="false" Priority="61" Name="Light List Accent 5"/>
  <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 5"/>
  <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 5"/>
  <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 5"/>
  <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 5"/>
  <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 5"/>
  <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 5"/>
  <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 5"/>
  <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 5"/>
  <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 5"/>
  <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 5"/>
  <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 5"/>
  <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 5"/>
  <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 6"/>
  <w:LsdException Locked="false" Priority="61" Name="Light List Accent 6"/>
  <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 6"/>
  <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 6"/>
  <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 6"/>
  <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 6"/>
  <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 6"/>
  <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 6"/>
  <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 6"/>
  <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 6"/>
  <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 6"/>
  <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 6"/>
  <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 6"/>
  <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 6"/>
  <w:LsdException Locked="false" Priority="19" QFormat="true"
   Name="Subtle Emphasis"/>
  <w:LsdException Locked="false" Priority="21" QFormat="true"
   Name="Intense Emphasis"/>
  <w:LsdException Locked="false" Priority="31" QFormat="true"
   Name="Subtle Reference"/>
  <w:LsdException Locked="false" Priority="32" QFormat="true"
   Name="Intense Reference"/>
  <w:LsdException Locked="false" Priority="33" QFormat="true" Name="Book Title"/>
  <w:LsdException Locked="false" Priority="37" SemiHidden="true"
   UnhideWhenUsed="true" Name="Bibliography"/>
  <w:LsdException Locked="false" Priority="39" SemiHidden="true"
   UnhideWhenUsed="true" QFormat="true" Name="TOC Heading"/>
  <w:LsdException Locked="false" Priority="41" Name="Plain Table 1"/>
  <w:LsdException Locked="false" Priority="42" Name="Plain Table 2"/>
  <w:LsdException Locked="false" Priority="43" Name="Plain Table 3"/>
  <w:LsdException Locked="false" Priority="44" Name="Plain Table 4"/>
  <w:LsdException Locked="false" Priority="45" Name="Plain Table 5"/>
  <w:LsdException Locked="false" Priority="40" Name="Grid Table Light"/>
  <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light"/>
  <w:LsdException Locked="false" Priority="47" Name="Grid Table 2"/>
  <w:LsdException Locked="false" Priority="48" Name="Grid Table 3"/>
  <w:LsdException Locked="false" Priority="49" Name="Grid Table 4"/>
  <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark"/>
  <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful"/>
  <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful"/>
  <w:LsdException Locked="false" Priority="46"
   Name="Grid Table 1 Light Accent 1"/>
  <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 1"/>
  <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 1"/>
  <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 1"/>
  <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 1"/>
  <w:LsdException Locked="false" Priority="51"
   Name="Grid Table 6 Colorful Accent 1"/>
  <w:LsdException Locked="false" Priority="52"
   Name="Grid Table 7 Colorful Accent 1"/>
  <w:LsdException Locked="false" Priority="46"
   Name="Grid Table 1 Light Accent 2"/>
  <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 2"/>
  <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 2"/>
  <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 2"/>
  <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 2"/>
  <w:LsdException Locked="false" Priority="51"
   Name="Grid Table 6 Colorful Accent 2"/>
  <w:LsdException Locked="false" Priority="52"
   Name="Grid Table 7 Colorful Accent 2"/>
  <w:LsdException Locked="false" Priority="46"
   Name="Grid Table 1 Light Accent 3"/>
  <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 3"/>
  <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 3"/>
  <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 3"/>
  <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 3"/>
  <w:LsdException Locked="false" Priority="51"
   Name="Grid Table 6 Colorful Accent 3"/>
  <w:LsdException Locked="false" Priority="52"
   Name="Grid Table 7 Colorful Accent 3"/>
  <w:LsdException Locked="false" Priority="46"
   Name="Grid Table 1 Light Accent 4"/>
  <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 4"/>
  <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 4"/>
  <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 4"/>
  <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 4"/>
  <w:LsdException Locked="false" Priority="51"
   Name="Grid Table 6 Colorful Accent 4"/>
  <w:LsdException Locked="false" Priority="52"
   Name="Grid Table 7 Colorful Accent 4"/>
  <w:LsdException Locked="false" Priority="46"
   Name="Grid Table 1 Light Accent 5"/>
  <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 5"/>
  <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 5"/>
  <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 5"/>
  <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 5"/>
  <w:LsdException Locked="false" Priority="51"
   Name="Grid Table 6 Colorful Accent 5"/>
  <w:LsdException Locked="false" Priority="52"
   Name="Grid Table 7 Colorful Accent 5"/>
  <w:LsdException Locked="false" Priority="46"
   Name="Grid Table 1 Light Accent 6"/>
  <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 6"/>
  <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 6"/>
  <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 6"/>
  <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 6"/>
  <w:LsdException Locked="false" Priority="51"
   Name="Grid Table 6 Colorful Accent 6"/>
  <w:LsdException Locked="false" Priority="52"
   Name="Grid Table 7 Colorful Accent 6"/>
  <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light"/>
  <w:LsdException Locked="false" Priority="47" Name="List Table 2"/>
  <w:LsdException Locked="false" Priority="48" Name="List Table 3"/>
  <w:LsdException Locked="false" Priority="49" Name="List Table 4"/>
  <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark"/>
  <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful"/>
  <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful"/>
  <w:LsdException Locked="false" Priority="46"
   Name="List Table 1 Light Accent 1"/>
  <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 1"/>
  <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 1"/>
  <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 1"/>
  <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 1"/>
  <w:LsdException Locked="false" Priority="51"
   Name="List Table 6 Colorful Accent 1"/>
  <w:LsdException Locked="false" Priority="52"
   Name="List Table 7 Colorful Accent 1"/>
  <w:LsdException Locked="false" Priority="46"
   Name="List Table 1 Light Accent 2"/>
  <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 2"/>
  <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 2"/>
  <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 2"/>
  <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 2"/>
  <w:LsdException Locked="false" Priority="51"
   Name="List Table 6 Colorful Accent 2"/>
  <w:LsdException Locked="false" Priority="52"
   Name="List Table 7 Colorful Accent 2"/>
  <w:LsdException Locked="false" Priority="46"
   Name="List Table 1 Light Accent 3"/>
  <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 3"/>
  <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 3"/>
  <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 3"/>
  <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 3"/>
  <w:LsdException Locked="false" Priority="51"
   Name="List Table 6 Colorful Accent 3"/>
  <w:LsdException Locked="false" Priority="52"
   Name="List Table 7 Colorful Accent 3"/>
  <w:LsdException Locked="false" Priority="46"
   Name="List Table 1 Light Accent 4"/>
  <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 4"/>
  <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 4"/>
  <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 4"/>
  <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 4"/>
  <w:LsdException Locked="false" Priority="51"
   Name="List Table 6 Colorful Accent 4"/>
  <w:LsdException Locked="false" Priority="52"
   Name="List Table 7 Colorful Accent 4"/>
  <w:LsdException Locked="false" Priority="46"
   Name="List Table 1 Light Accent 5"/>
  <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 5"/>
  <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 5"/>
  <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 5"/>
  <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 5"/>
  <w:LsdException Locked="false" Priority="51"
   Name="List Table 6 Colorful Accent 5"/>
  <w:LsdException Locked="false" Priority="52"
   Name="List Table 7 Colorful Accent 5"/>
  <w:LsdException Locked="false" Priority="46"
   Name="List Table 1 Light Accent 6"/>
  <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 6"/>
  <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 6"/>
  <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 6"/>
  <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 6"/>
  <w:LsdException Locked="false" Priority="51"
   Name="List Table 6 Colorful Accent 6"/>
  <w:LsdException Locked="false" Priority="52"
   Name="List Table 7 Colorful Accent 6"/>
 </w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>

<![endif]-->]]></content:encoded>
    </item>
  </channel>
</rss>