<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SQLvariations: SQL Server, a little PowerShell, maybe some Hyper-V &#187; Code</title>
	<atom:link href="http://sqlvariant.com/wordpress/index.php/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://sqlvariant.com/wordpress</link>
	<description>maybe even the occasional ETL tidbit</description>
	<lastBuildDate>Wed, 01 Feb 2012 20:15:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>PowerShell Presentation at SQLskills open-mic night</title>
		<link>http://sqlvariant.com/wordpress/index.php/2011/12/powershell-presentation-at-sqlskills-open-mic-night/</link>
		<comments>http://sqlvariant.com/wordpress/index.php/2011/12/powershell-presentation-at-sqlskills-open-mic-night/#comments</comments>
		<pubDate>Fri, 09 Dec 2011 15:51:31 +0000</pubDate>
		<dc:creator>Aaron Nelson</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Training Event]]></category>
		<category><![CDATA[Database Sizes]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[SQLskills]]></category>
		<category><![CDATA[Table Sizes]]></category>

		<guid isPermaLink="false">http://sqlvariant.com/wordpress/?p=2294</guid>
		<description><![CDATA[Kimberly Tripp ( blog &#124; twitter ) and Paul Randal ( blog &#124; twitter ) SQLsklls are here in Atlanta this week.  Last night they held an ‘open mic’ night and allowed anyone who wanted to present a topic 15 minutes to show something to the rest of the class.  Surprise, surprise I decided to talk about PowerShell. I received multiple requests to post the scripts I used before I even had a chance to sit down so here they are. If you were in the class and would like to use these and don’t even know where to start with PowerShell have a look at my “Resources for my SQL Server PowerShell Extensions webcast” post. If you ever get a chance to attend one of their classes and present in front of Paul and Kim TAKE IT!   Even if it’s just about your SSMS tips or how to work around a problem you encountered.  The feedback you get is *more* than worth it!]]></description>
			<content:encoded><![CDATA[<p>Kimberly Tripp ( <a href="http://www.sqlskills.com/blogs/Kimberly">blog</a> | <a href="http://twitter.com/#!/KimberlyLTripp">twitter</a> ) and Paul Randal ( <a href="http://www.sqlskills.com/blogs/paul/">blog</a> | <a href="http://twitter.com/#!/PaulRandal">twitter</a> ) <a href="http://www.sqlskills.com/default.asp"><strong>SQLsklls</strong></a> are here in <a href="http://www.sqlskills.com/Atlanta-20111205.asp"><strong>Atlanta this week</strong></a><strong>.</strong>  Last night they held an ‘open mic’ night and allowed anyone who wanted to present a topic 15 minutes to show something to the rest of the class.  Surprise, surprise I decided to talk about PowerShell.</p>
<p>I received multiple requests to post the scripts I used before I even had a chance to sit down so <a href="http://SQLvariant.com/BlogSupport/Scripts/PowerShell/TableSizes_AndCompression.zip"><strong>here they are</strong></a><strong>.</strong></p>
<p>If you were in the class and would like to use these and don’t even know where to start with PowerShell have a look at my “<a href="http://sqlvariant.com/wordpress/index.php/2011/10/resources-for-my-sql-server-powershell-extensions-webcast/"><strong>Resources for my SQL Server PowerShell Extensions webcast</strong></a>” post.</p>
<p>If you ever get a chance to attend one of their classes and present in front of Paul and Kim TAKE IT! <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />   Even if it’s just about your SSMS tips or how to work around a problem you encountered.  The feedback you get is *more* than worth it!</p>
]]></content:encoded>
			<wfw:commentRss>http://sqlvariant.com/wordpress/index.php/2011/12/powershell-presentation-at-sqlskills-open-mic-night/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Quick Blog: Grabbing basic machine info with PowerShell</title>
		<link>http://sqlvariant.com/wordpress/index.php/2011/11/quick-blog-grabbing-basic-machine-info-with-powershell/</link>
		<comments>http://sqlvariant.com/wordpress/index.php/2011/11/quick-blog-grabbing-basic-machine-info-with-powershell/#comments</comments>
		<pubDate>Tue, 29 Nov 2011 14:33:00 +0000</pubDate>
		<dc:creator>Aaron Nelson</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[functions]]></category>

		<guid isPermaLink="false">http://sqlvariant.com/wordpress/index.php/2011/11/quick-blog-grabbing-basic-machine-info-with-powershell/</guid>
		<description><![CDATA[The other day I needed to track down how much RAM a couple of our servers had installed.  A few days later I needed to verify that a couple of them were in fact 64-bit and not 32-bit.  I decided I wanted to be able to get at this basic info any time that I wanted without having to remember all the syntax so I built it into a PowerShell function. Building a PowerShell function is almost as easy easier than building a stored procedure around a select statement in SQL.  The reason PowerShell is easier than SQL is that when you have a parameter that you are passing in, you can give it a data type, but you don’t have to. For the function below I gave it a default value of the local machine but you can pass in a machine name that you are trying to get to. Just copy the code below into an ISE window and hit F5. function Get-MachineInfo($ServerName="localhost") { get-wmiobject win32_computersystem -ComputerName $ServerName &#124; select DNSHostName, Manufacturer, Model, SystemType , @{Name="TotalPhysicalMemoryInMB";Expression={"{0:n2}" -f($_.TotalPhysicalMemory/1mb)}}, NumberOfLogicalProcessors, NumberOfProcessors, CurrentTimeZone, DaylightInEffect }# End Get-MachineInfo After you’ve done that, to call the stored proc function simply type in the name ( Get-MachineInfo ) to the prompt at the bottom and hit enter]]></description>
			<content:encoded><![CDATA[<p>The other day I needed to track down how much RAM a couple of our servers had installed.  A few days later I needed to verify that a couple of them were in fact 64-bit and not 32-bit.  I decided I wanted to be able to get at this basic info any time that I wanted without having to remember all the syntax so I built it into a PowerShell function.</p>
<p>Building a PowerShell function is <span style="text-decoration: line-through;">almost as easy</span> easier than building a stored procedure around a select statement in SQL.  The reason PowerShell is easier than SQL is that when you have a parameter that you are passing in, you <strong><em>can</em></strong> give it a data type, but you <span style="text-decoration: underline;">don’t have to</span>.</p>
<p>For the function below I gave it a default value of the local machine but you can pass in a machine name that you are trying to get to.</p>
<p>Just copy the code below into an ISE window and hit F5.</p>
<pre class='PowerShellColorizedScript'><span style='color:#00008b'>function</span> <span style='color:#8a2be2'>Get-MachineInfo</span><span style='color:#000000'>(</span><span style='color:#ff4500'>$ServerName</span><span style='color:#a9a9a9'>=</span><span style='color:#8b0000'>"localhost"</span><span style='color:#000000'>)</span>
<span style='color:#000000'>{</span>
<span style='color:#0000ff'>get-wmiobject</span> <span style='color:#8a2be2'>win32_computersystem</span> <span style='color:#000080'>-ComputerName</span> <span style='color:#ff4500'>$ServerName</span> <span style='color:#a9a9a9'>|</span>
<span style='color:#0000ff'>select</span> <span style='color:#8a2be2'>DNSHostName</span><span style='color:#a9a9a9'>,</span> <span style='color:#8a2be2'>Manufacturer</span><span style='color:#a9a9a9'>,</span> <span style='color:#8a2be2'>Model</span><span style='color:#a9a9a9'>,</span> <span style='color:#8a2be2'>SystemType</span> <span style='color:#a9a9a9'>,</span>
        <span style='color:#000000'>@{</span><span style='color:#000000'>Name</span><span style='color:#a9a9a9'>=</span><span style='color:#8b0000'>"TotalPhysicalMemoryInMB"</span><span style='color:#000000'>;</span><span style='color:#000000'>Expression</span><span style='color:#a9a9a9'>=</span><span style='color:#000000'>{</span><span style='color:#8b0000'>"{0:n2}"</span> <span style='color:#a9a9a9'>-f</span><span style='color:#000000'>(</span><span style='color:#ff4500'>$_</span><span style='color:#a9a9a9'>.</span><span style='color:#000000'>TotalPhysicalMemory</span><span style='color:#a9a9a9'>/</span><span style='color:#800080'>1mb</span><span style='color:#000000'>)</span><span style='color:#000000'>}</span><span style='color:#000000'>}</span><span style='color:#a9a9a9'>,</span>
        <span style='color:#8a2be2'>NumberOfLogicalProcessors</span><span style='color:#a9a9a9'>,</span> <span style='color:#8a2be2'>NumberOfProcessors</span><span style='color:#a9a9a9'>,</span> <span style='color:#8a2be2'>CurrentTimeZone</span><span style='color:#a9a9a9'>,</span> <span style='color:#8a2be2'>DaylightInEffect</span>
<span style='color:#000000'>}</span><span style='color:#006400'># End Get-MachineInfo</span></pre>
<p>After you’ve done that, to call the <span style="text-decoration: line-through;">stored proc</span> function simply type in the name ( <span style="color: #0000ff; font-family: Segoe UI Semibold; font-size: small;">Get-MachineInfo</span> ) to the prompt at the bottom and hit enter</p>
<p><a href="http://sqlvariant.com/wordpress/wp-content/uploads/2011/11/image2.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://sqlvariant.com/wordpress/wp-content/uploads/2011/11/image_thumb.png" alt="image" width="473" height="342" border="0" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://sqlvariant.com/wordpress/index.php/2011/11/quick-blog-grabbing-basic-machine-info-with-powershell/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Scripts for presentation today at the 2011 PASS Summit</title>
		<link>http://sqlvariant.com/wordpress/index.php/2011/10/scripts-for-presentation-today-at-the-2011-pass-summit/</link>
		<comments>http://sqlvariant.com/wordpress/index.php/2011/10/scripts-for-presentation-today-at-the-2011-pass-summit/#comments</comments>
		<pubDate>Thu, 13 Oct 2011 21:42:12 +0000</pubDate>
		<dc:creator>Aaron Nelson</dc:creator>
				<category><![CDATA[PASS]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[PASS Summit]]></category>
		<category><![CDATA[PASS Summit 2011]]></category>
		<category><![CDATA[Presentation]]></category>

		<guid isPermaLink="false">http://sqlvariant.com/wordpress/index.php/2011/10/scripts-for-presentation-today-at-the-2011-pass-summit/</guid>
		<description><![CDATA[I’m presenting at the PASS Summit today and just wanted to post the scripts I plan on using.  If you’re following along and you’re new to PowerShell I recommend that you have a look at this article I wrote earlier this year: Day Zero with PowerShell Table Size Store Results Compress Tables Compress Indexes Store Results Process Cube Backup Database –PassThru Download Denali CTP Grab Configuration Info New Get-DisksSpace try to pass from Reg servers w/ Group Email Space Report CSV with Bulk Insert Import CSV with Out-DataTable Allen Kinsel – Logs SQL Saturday – Navigate Event Schedule XML]]></description>
			<content:encoded><![CDATA[<p>I’m presenting at the PASS Summit today and just wanted to <a href="http://SQLvariant.com/BlogSupport/Scripts/PowerShell/PASSSummit2011-Dozen.zip"><strong><span style="font-size: x-small;">post the scripts</span></strong></a> I plan on using.  If you’re following along and you’re new to PowerShell I recommend that you have a look at this article I wrote earlier this year: <a href="http://www.sqlservercentral.com/articles/powershell/73288/"><strong><span style="font-size: x-small;">Day Zero with PowerShell </span></strong></a></p>
<ol>
<li>Table Size</li>
<ol>
<li>Store Results</li>
</ol>
<li>Compress Tables</li>
<ol>
<li>Compress Indexes</li>
<li>Store Results</li>
</ol>
<li>Process Cube</li>
<li>Backup Database –PassThru</li>
<li>Download Denali CTP</li>
<li>Grab Configuration Info</li>
<li>New Get-DisksSpace try to pass from Reg servers w/ Group</li>
<li>Email Space Report</li>
<li>CSV with Bulk Insert</li>
<li>Import CSV with Out-DataTable</li>
<li>Allen Kinsel – Logs</li>
<li>SQL Saturday – Navigate Event Schedule XML</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://sqlvariant.com/wordpress/index.php/2011/10/scripts-for-presentation-today-at-the-2011-pass-summit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Whats in my PowerShell Profile</title>
		<link>http://sqlvariant.com/wordpress/index.php/2011/10/whats-in-my-powershell-profile/</link>
		<comments>http://sqlvariant.com/wordpress/index.php/2011/10/whats-in-my-powershell-profile/#comments</comments>
		<pubDate>Tue, 11 Oct 2011 20:08:17 +0000</pubDate>
		<dc:creator>Aaron Nelson</dc:creator>
				<category><![CDATA[PASS]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[PASS Summit]]></category>
		<category><![CDATA[PASS Summit 2011]]></category>

		<guid isPermaLink="false">http://sqlvariant.com/wordpress/index.php/2011/10/whats-in-my-powershell-profile/</guid>
		<description><![CDATA[Here are two zip files.  The first file is my profile and the second zip file is the scripts that my profiles references.  These are just some of the tools I find useful for enhancing PowerShell.]]></description>
			<content:encoded><![CDATA[<p>Here are two zip files.  The first file is <a href="http://sqlvariant.com/BlogSupport/Scripts/PowerShell/BasicProfile.zip">my profile</a> and the <a href="http://SQLvariant.com/BlogSupport/Scripts/PowerShell/ScriptsInMyProfile.zip">second zip file</a> is the scripts that my profiles references.  These are just some of the tools I find useful for enhancing PowerShell.</p>
]]></content:encoded>
			<wfw:commentRss>http://sqlvariant.com/wordpress/index.php/2011/10/whats-in-my-powershell-profile/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Resources for my SQL Server PowerShell Extensions webcast</title>
		<link>http://sqlvariant.com/wordpress/index.php/2011/10/resources-for-my-sql-server-powershell-extensions-webcast/</link>
		<comments>http://sqlvariant.com/wordpress/index.php/2011/10/resources-for-my-sql-server-powershell-extensions-webcast/#comments</comments>
		<pubDate>Wed, 05 Oct 2011 21:03:05 +0000</pubDate>
		<dc:creator>Aaron Nelson</dc:creator>
				<category><![CDATA[Denali CTP3]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Presentations]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQLPSX]]></category>
		<category><![CDATA[Webcast]]></category>

		<guid isPermaLink="false">http://sqlvariant.com/wordpress/index.php/2011/10/resources-for-my-sql-server-powershell-extensions-webcast/</guid>
		<description><![CDATA[I did another webcast for the Secrets of SQL Server webcast series today.  In the today’s webcast we built on some things I had demoed in a prior webcast and showed how PowerShell in conjunction with SQLPSX can really help you solve some common problems DBAs face. I showed how you could pull size and free space information from all of your data files, then used the same technique to pull size information from all of your tables across every database on an instance.  Later we created a database and some tables, and then showed how to do some basic login comparisons, all with SQLPSX. In addition, we stored the results of the frees pace and table size information in a database using the Out-DataTable and Write-DataTable functions.  Finally we wrapped up with a quick demo on how the new SQL Server cmdlets inside of the SQLPS Module in Denali combined with some new functionality in PowerShell v3 CTP1 can really make backing up a database with PowerShell a lot easier. Here’s what you’ll need to recreate today’s demos; Download and install SQLPSX The Out-DataTable function from the TechNet script repository The Write-DataTable function from the TechNet script repository and these scripts Oh, and here are the handful of slides that I had I hope I see you next week at the PASS Summit or next month during another webcast, this time on customizing your own functions to work with the SMO.]]></description>
			<content:encoded><![CDATA[<p><a href="http://a1100.v46030f.c46030.g.vm.akamaistream.net/7/1100/46030/v0001/smb2.download.akamai.com/46030/Idera/100511-SQLSP01/100511-SQLSP01_archive.wmv"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; float: right; padding-top: 0px; border: 0px;" title="image" src="http://sqlvariant.com/wordpress/wp-content/uploads/2011/10/image_thumb.png" alt="image" width="220" height="244" align="right" border="0" /></a>I did another<strong> <a href="http://a1100.v46030f.c46030.g.vm.akamaistream.net/7/1100/46030/v0001/smb2.download.akamai.com/46030/Idera/100511-SQLSP01/100511-SQLSP01_archive.wmv">webcast </a></strong>for the <a href="http://www.idera.com/Education/SQL-server-Webcasts/">Secrets of SQL Server</a> webcast series today.  In the today’s webcast we built on some things I had demoed in a <a href="http://www.idera.com/Events/RegisterWC.aspx?EventID=232">prior webcast</a> and showed how PowerShell in conjunction with <strong><a href="http://sqlpsx.codeplex.com/">SQLPSX</a></strong> can really help you solve some common problems DBAs face.</p>
<p>I showed how you could pull size and free space information from all of your data files, then used the same technique to pull size information from all of your tables across every database on an instance.  Later we created a database and some tables, and then showed how to do some basic login comparisons, all with SQLPSX.</p>
<p>In addition, we stored the results of the frees pace and table size information in a database using the Out-DataTable and Write-DataTable functions.  Finally we wrapped up with a quick demo on how the new SQL Server cmdlets inside of the SQLPS Module in Denali combined with some new functionality in PowerShell v3 CTP1 can really make backing up a database with PowerShell a lot easier.</p>
<p>Here’s what you’ll need to recreate today’s demos;</p>
<ul>
<li>Download and install <a href="http://sqlpsx.codeplex.com/"><strong>SQLPSX</strong></a></li>
<li>The <a href="http://gallery.technet.microsoft.com/scriptcenter/4208a159-a52e-4b99-83d4-8048468d29dd"><strong>Out-DataTable</strong></a> function from the TechNet script repository</li>
<li>The <strong><a href="http://gallery.technet.microsoft.com/scriptcenter/2fdeaf8d-b164-411c-9483-99413d6053ae">Write-DataTable</a></strong> function from the TechNet script repository</li>
<li>and <strong><a href="http://SQLvariant.com/BlogSupport/Scripts/PowerShell/SoSS_Webcast2.zip">these scripts</a></strong></li>
<li>Oh, and here are the handful of <a href="http://SQLvariant.com/BlogSupport/SlideDecks/SoSS-GetMoreDoneWithSQLPSX.pptx">slides</a> that I had</li>
</ul>
<p>I hope I see you next week at the PASS Summit or next month during another webcast, this time on customizing your own functions to work with the SMO.</p>
]]></content:encoded>
			<wfw:commentRss>http://sqlvariant.com/wordpress/index.php/2011/10/resources-for-my-sql-server-powershell-extensions-webcast/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://a1100.v46030f.c46030.g.vm.akamaistream.net/7/1100/46030/v0001/smb2.download.akamai.com/46030/Idera/100511-SQLSP01/100511-SQLSP01_archive.wmv" length="0" type="video/asf" />
		</item>
		<item>
		<title>New PowerShell Cmdlets in SQL Denali CTP3</title>
		<link>http://sqlvariant.com/wordpress/index.php/2011/07/new-powershell-cmdlets-in-sql-denali-ctp3/</link>
		<comments>http://sqlvariant.com/wordpress/index.php/2011/07/new-powershell-cmdlets-in-sql-denali-ctp3/#comments</comments>
		<pubDate>Tue, 12 Jul 2011 13:38:27 +0000</pubDate>
		<dc:creator>Aaron Nelson</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[CTP3]]></category>
		<category><![CDATA[Denali]]></category>
		<category><![CDATA[IntegrationServices]]></category>
		<category><![CDATA[SQLAS]]></category>
		<category><![CDATA[XEvent]]></category>

		<guid isPermaLink="false">http://sqlvariant.com/wordpress/?p=2243</guid>
		<description><![CDATA[CTP3 of SQL Denali is finally publicly available! I woke up at 5 am this morning to kick off my download.  I&#8217;ve finished the install and I&#8217;m happy that I can finally report that we have new cmdlets for SQL Server.  First off, after running Get-Module -ListAvailable I saw: Manifest   SQLASCMDLETS Manifest   SQLPS This means that SQLPS inside of SQL Agent should finally allow you to import a module during your job step.  There is now a Function called SQLServer that, from what I can tell, is the SQLServer Provider.  When under PS SQLSERVER:\&#62; if you do a dir &#124; Select pschildname you will find the following list: PSChildName &#8212;&#8212;&#8212;&#8211; SQL SQLPolicy SQLRegistration DataCollection XEvent Utility DAC IntegrationServices SQLAS From my notes it looks like XEvent, IntegrationServices, and SQLAS are the directories that have been added here.  Can&#8217;t wait to try out the IntegrationServices portion!  [Update]: Apparently I may need a defaul instance install for this to work. I also noticed that Tab-Completion appears to be fixed!!    Also, SQL Registrations &#62; &#8216;Database Engine Server Group&#8217; are split up into instances like CMS was.  Not sure what that&#8217;s all about just yet.  In fact when I try to use it, it doesn&#8217;t seem to work.  Maybe I should read the help files.  But I think they may have just gotten CMS &#38; RS reversed.  CMS isn&#8217;t working for me either yet. When you drill down under XEvents and go to your Denali instaince you will see: Packages, &#38; Sessions.  I guess this means that I finally need to read Jonathat&#8217;s blog series on X-Events. When I imported the SQLPS module I received a warning about unapproved verbs.  Oh well, hopefully they&#8217;ll work that out soon.  Next I ran Get-Command -Module &#8220;SQLPS&#8221; and found the following list of cmdlets. Name Module Add-SqlAvailabilityDatabase SQLPS Add-SqlAvailabilityGroupListenerStaticIp SQLPS Backup-SqlDatabase SQLPS Convert-UrnToPath SQLPS Decode-SqlName SQLPS Disable-SqlHADRService SQLPS Enable-SqlHADRService SQLPS Encode-SqlName SQLPS Invoke-PolicyEvaluation SQLPS Invoke-Sqlcmd SQLPS Join-SqlAvailabilityGroup SQLPS New-SqlAvailabilityGroup SQLPS New-SqlAvailabilityGroupListener SQLPS New-SqlAvailabilityReplica SQLPS New-SqlHADREndpoint SQLPS Remove-SqlAvailabilityDatabase SQLPS Remove-SqlAvailabilityGroup SQLPS Remove-SqlAvailabilityReplica SQLPS Restore-SqlDatabase SQLPS Resume-SqlAvailabilityDatabase SQLPS Set-SqlAvailabilityGroup SQLPS Set-SqlAvailabilityGroupListener SQLPS Set-SqlAvailabilityReplica SQLPS Set-SqlHADREndpoint SQLPS SQLSERVER SQLPS Suspend-SqlAvailabilityDatabase SQLPS Switch-SqlAvailabilityGroup SQLPS Test-SqlAvailabilityGroup SQLPS Test-SqlAvailabilityReplica SQLPS Test-SqlDatabaseReplicaState SQLPS Analysis Services got some love too in the form of 11 cmdlets!  After inporting the SQLASCMDLETS module I ran this Get-Command -Module &#8220;SQLASCMDLETS&#8221; and found the following. Name Module Add-RoleMember SQLASCMDLETS Backup-ASDatabase SQLASCMDLETS Invoke-ASCmd SQLASCMDLETS Invoke-ProcessCube SQLASCMDLETS Invoke-ProcessDimension SQLASCMDLETS Invoke-ProcessPartition SQLASCMDLETS Merge-Partition SQLASCMDLETS New-RestoreFolder SQLASCMDLETS New-RestoreLocation SQLASCMDLETS Remove-RoleMember SQLASCMDLETS Restore-ASDatabase SQLASCMDLETS More news to follow soon!]]></description>
			<content:encoded><![CDATA[<p>CTP3 of SQL Denali is finally <a href="https://www.microsoft.com/betaexperience/pd/SQLDCTP3CTA/enus/default.aspx" target="_blank">publicly available</a>!</p>
<p>I woke up at 5 am this morning to kick off my download.  I&#8217;ve finished the install and I&#8217;m happy that I can finally report that we have new cmdlets for SQL Server. </p>
<p>First off, after running <span style="color: #0000ff;">Get-Module</span> <span style="color: #000080;">-ListAvailable</span> I saw:</p>
<p>Manifest   SQLASCMDLETS<br />
Manifest   SQLPS</p>
<p>This means that SQLPS inside of SQL Agent should finally allow you to import a module during your job step. </p>
<p>There is now a Function called SQLServer that, from what I can tell, is the SQLServer Provider.  When under PS SQLSERVER:\&gt; if you do a <span style="color: #0000ff;">dir</span> <span style="color: #a9a9a9;">|</span> <span style="color: #0000ff;">Select</span> <span style="color: #8a2be2;">pschildname</span> you will find the following list:</p>
<p>PSChildName<br />
&#8212;&#8212;&#8212;&#8211;<br />
SQL<br />
SQLPolicy<br />
SQLRegistration<br />
DataCollection<br />
<strong>XEvent</strong><br />
Utility<br />
DAC<br />
<strong>IntegrationServices</strong><br />
<strong>SQLAS</strong></p>
<p>From my notes it looks like <strong><span style="color: #003366;">XEvent</span></strong>, <strong><span style="color: #003366;">IntegrationServices</span></strong>, and <strong><span style="color: #003366;">SQLAS </span></strong>are the directories that have been added here.  Can&#8217;t wait to try out the IntegrationServices portion!  [Update]: Apparently I may need a defaul instance install for this to work.</p>
<p>I also noticed that <span style="color: #003300;"><strong>Tab-Completion </strong></span>appears to be fixed!!  <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />   Also, SQL Registrations &gt; &#8216;Database Engine Server Group&#8217; are split up into instances like CMS was.  Not sure what that&#8217;s all about just yet.  In fact when I try to use it, it doesn&#8217;t seem to work.  Maybe I should read the help files.  But I think they may have just gotten CMS &amp; RS reversed.  CMS isn&#8217;t working for me either yet.</p>
<p>When you drill down under XEvents and go to your Denali instaince you will see: Packages, &amp; Sessions.  I guess this means that I finally need to read Jonathat&#8217;s blog series on X-Events.</p>
<p>When I imported the SQLPS module I received a warning about unapproved verbs.  Oh well, hopefully they&#8217;ll work that out soon.  Next I ran <strong><span style="color: #0000ff;">Get-Command</span> <span style="color: #000080;">-Module</span> <span style="color: #8b0000;">&#8220;SQLPS&#8221;</span></strong> and found the following list of cmdlets.</p>
<table border="0" cellspacing="0" cellpadding="0" width="370">
<colgroup span="1">
<col span="1" width="267"></col>
<col span="1" width="103"></col>
</colgroup>
<tbody>
<tr height="20">
<td width="267" height="20">Name</td>
<td width="103">Module</td>
</tr>
<tr height="20">
<td height="20">Add-SqlAvailabilityDatabase</td>
<td>SQLPS</td>
</tr>
<tr height="20">
<td height="20">Add-SqlAvailabilityGroupListenerStaticIp</td>
<td>SQLPS</td>
</tr>
<tr height="20">
<td height="20">Backup-SqlDatabase</td>
<td>SQLPS</td>
</tr>
<tr height="20">
<td height="20">Convert-UrnToPath</td>
<td>SQLPS</td>
</tr>
<tr height="20">
<td height="20">Decode-SqlName</td>
<td>SQLPS</td>
</tr>
<tr height="20">
<td height="20">Disable-SqlHADRService</td>
<td>SQLPS</td>
</tr>
<tr height="20">
<td height="20">Enable-SqlHADRService</td>
<td>SQLPS</td>
</tr>
<tr height="20">
<td height="20">Encode-SqlName</td>
<td>SQLPS</td>
</tr>
<tr height="20">
<td height="20">Invoke-PolicyEvaluation</td>
<td>SQLPS</td>
</tr>
<tr height="20">
<td height="20">Invoke-Sqlcmd</td>
<td>SQLPS</td>
</tr>
<tr height="20">
<td height="20">Join-SqlAvailabilityGroup</td>
<td>SQLPS</td>
</tr>
<tr height="20">
<td height="20">New-SqlAvailabilityGroup</td>
<td>SQLPS</td>
</tr>
<tr height="20">
<td height="20">New-SqlAvailabilityGroupListener</td>
<td>SQLPS</td>
</tr>
<tr height="20">
<td height="20">New-SqlAvailabilityReplica</td>
<td>SQLPS</td>
</tr>
<tr height="20">
<td height="20">New-SqlHADREndpoint</td>
<td>SQLPS</td>
</tr>
<tr height="20">
<td height="20">Remove-SqlAvailabilityDatabase</td>
<td>SQLPS</td>
</tr>
<tr height="20">
<td height="20">Remove-SqlAvailabilityGroup</td>
<td>SQLPS</td>
</tr>
<tr height="20">
<td height="20">Remove-SqlAvailabilityReplica</td>
<td>SQLPS</td>
</tr>
<tr height="20">
<td height="20">Restore-SqlDatabase</td>
<td>SQLPS</td>
</tr>
<tr height="20">
<td height="20">Resume-SqlAvailabilityDatabase</td>
<td>SQLPS</td>
</tr>
<tr height="20">
<td height="20">Set-SqlAvailabilityGroup</td>
<td>SQLPS</td>
</tr>
<tr height="20">
<td height="20">Set-SqlAvailabilityGroupListener</td>
<td>SQLPS</td>
</tr>
<tr height="20">
<td height="20">Set-SqlAvailabilityReplica</td>
<td>SQLPS</td>
</tr>
<tr height="20">
<td height="20">Set-SqlHADREndpoint</td>
<td>SQLPS</td>
</tr>
<tr height="20">
<td height="20">SQLSERVER</td>
<td>SQLPS</td>
</tr>
<tr height="20">
<td height="20">Suspend-SqlAvailabilityDatabase</td>
<td>SQLPS</td>
</tr>
<tr height="20">
<td height="20">Switch-SqlAvailabilityGroup</td>
<td>SQLPS</td>
</tr>
<tr height="20">
<td height="20">Test-SqlAvailabilityGroup</td>
<td>SQLPS</td>
</tr>
<tr height="20">
<td height="20">Test-SqlAvailabilityReplica</td>
<td>SQLPS</td>
</tr>
<tr height="20">
<td height="20">Test-SqlDatabaseReplicaState</td>
<td>SQLPS</td>
</tr>
</tbody>
</table>
<p>Analysis Services got some love too in the form of 11 cmdlets!  After inporting the SQLASCMDLETS module I ran this <span style="color: #0000ff;">Get-Command</span> <span style="color: #000080;">-Module</span> <span style="color: #8b0000;">&#8220;SQLASCMDLETS&#8221;</span> and found the following.</p>
<table border="0" cellspacing="0" cellpadding="0" width="370">
<colgroup span="1">
<col span="1" width="267"></col>
<col span="1" width="103"></col>
</colgroup>
<tbody>
<tr height="20">
<td width="267" height="20">Name</td>
<td width="103">Module</td>
</tr>
<tr height="20">
<td height="20">Add-RoleMember</td>
<td>SQLASCMDLETS</td>
</tr>
<tr height="20">
<td height="20">Backup-ASDatabase</td>
<td>SQLASCMDLETS</td>
</tr>
<tr height="20">
<td height="20">Invoke-ASCmd</td>
<td>SQLASCMDLETS</td>
</tr>
<tr height="20">
<td height="20">Invoke-ProcessCube</td>
<td>SQLASCMDLETS</td>
</tr>
<tr height="20">
<td height="20">Invoke-ProcessDimension</td>
<td>SQLASCMDLETS</td>
</tr>
<tr height="20">
<td height="20">Invoke-ProcessPartition</td>
<td>SQLASCMDLETS</td>
</tr>
<tr height="20">
<td height="20">Merge-Partition</td>
<td>SQLASCMDLETS</td>
</tr>
<tr height="20">
<td height="20">New-RestoreFolder</td>
<td>SQLASCMDLETS</td>
</tr>
<tr height="20">
<td height="20">New-RestoreLocation</td>
<td>SQLASCMDLETS</td>
</tr>
<tr height="20">
<td height="20">Remove-RoleMember</td>
<td>SQLASCMDLETS</td>
</tr>
<tr height="20">
<td height="20">Restore-ASDatabase</td>
<td>SQLASCMDLETS</td>
</tr>
</tbody>
</table>
<p>More news to follow soon!</p>
]]></content:encoded>
			<wfw:commentRss>http://sqlvariant.com/wordpress/index.php/2011/07/new-powershell-cmdlets-in-sql-denali-ctp3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Emailing tempdb Query Results to Paul Randal with PowerShell</title>
		<link>http://sqlvariant.com/wordpress/index.php/2011/02/emailing-tempdb-query-results-to-paul-randal-with-powershell/</link>
		<comments>http://sqlvariant.com/wordpress/index.php/2011/02/emailing-tempdb-query-results-to-paul-randal-with-powershell/#comments</comments>
		<pubDate>Wed, 23 Feb 2011 19:27:52 +0000</pubDate>
		<dc:creator>Aaron Nelson</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Syndicated]]></category>

		<guid isPermaLink="false">http://sqlvariant.com/wordpress/index.php/2011/02/emailing-tempdb-query-results-to-paul-randal-with-powershell/</guid>
		<description><![CDATA[I was referred to someone on twitter today who wants to email query results without setting up database mail.  I explained this in Post 6 of PowerShell Week at SQL University but that example was somewhat complicated. Instead, I thought I’d whip up a new example using Paul’s latest survey.  Paul want’s to know know how many cores your instances have and how many data files that tempdb has. Paul’s query is pretty simple: SELECT os.Cores, df.Files FROM (SELECT COUNT(*) AS Cores FROM sys.dm_os_schedulers WHERE status = 'VISIBLE ONLINE') AS os, (SELECT COUNT(*) AS Files FROM tempdb.sys.database_files WHERE type_desc = 'ROWS') AS df; GO I simply took that query and wrapped it with almost the same code that I used at SQL University.  The difference allows me to show off two new tricks.  First, I separated out the part that grabs the list of servers from your Registered Servers to happen before the foreach loop.  I had received feedback from a reader that A) Having it there made it hard to read on my website, and B) it simplified the logic flow.  It also has the added benefits of performing faster when you’re running against hundreds of instances like me, and making it a little more clear how to swap it out when you want to use something besides Registered Servers to list your instances.  For more information on the different data sources that you can use for reading in a list of servers have a look here at Post 5. Second I added this $S++; it is a little piece of code to enumerate the instances for you.  Last time I had written the results to a table and then read them out using DENSE_RANK but since we don’t have multiple results this time [and because I love showing off cool PowerShell code] I used this instead. $ServerList = dir -recurse SQLSERVER:\SQLRegistration\'Database Engine Server Group'\ &#124; where {$_.Mode -ne "d"} foreach ($RegisteredSQLs in $ServerList ) { $S++; $dt+=invoke-sqlcmd2 -ServerInstance $RegisteredSQLs.ServerName -database master -Query " (SELECT COUNT(*) AS Cores FROM sys.dm_os_schedulers WHERE status = 'VISIBLE ONLINE') AS os, (SELECT COUNT(*) AS Files FROM tempdb.sys.database_files WHERE type_desc = 'ROWS') AS df" -As 'DataTable' } $MultipleResults = $dt &#124; ConvertTo-Html -Property Instance, Cores, Files &#124; Out-String; Send-MailMessage -To paul@SQLskills.com ` -Subject "tempdb Survey Results" ` –From YourEmailAddress@GoesHere.com ` -SmtpServer YourSMTPServerGoesHere ` -Body $MultipleResults -BodyAsHtml Hopefully this will help you email query results to your heart&#8217;s content   Big thanks to TJay Belt ( blog &#124; @TJayBelt ) for pointing out this request on the #SQLHelp hotline to me.  I&#8217;ve done this tons of times myself and I LOVE that anyone can walk up with a question and when people don&#8217;t have the answer they still do what they can to help them out right away.  I less than three community!! Please Note: DO NOT SPAM Paul Randal! You should probably try emailing this to yourself a time or two before you decide to send it to him. I’m using Chad Miller’s (Blog&#124;Twitter) invoke-sqlcmd2 to output the results as a data table (you’ll need that). Finally a friendly reminder that unlike SQL Server, PowerShell persists variables so if you run this multiple times you’ll want to clear out the $dt variable like this: $dt=$null.]]></description>
			<content:encoded><![CDATA[<p><a href="http://sqlvariant.com/wordpress/wp-content/uploads/2011/02/image3.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; float: right; padding-top: 0px; border-width: 0px;" title="image" src="http://sqlvariant.com/wordpress/wp-content/uploads/2011/02/image_thumb1.png" border="0" alt="image" width="476" height="159" align="right" /></a>I was referred to someone on twitter today who wants to email query results without setting up database mail.  I explained this in <a href="http://sqlvariant.com/wordpress/index.php/2011/01/powershell-week-at-sql-university-post-6/"><strong>Post 6 of PowerShell Week at SQL University</strong></a> but that example was somewhat complicated. Instead, I thought I’d whip up a new example using <a href="http://www.sqlskills.com/BLOGS/PAUL/post/Survey-how-is-your-tempdb-configured.aspx">Paul’s latest survey</a>.  Paul want’s to know know how many cores your instances have and how many data files that tempdb has.</p>
<p>Paul’s query is pretty simple:</p>
<p><code style="font-size: 12px;"><span style="color: blue;">SELECT </span><span style="color: black;">os.Cores</span><span style="color: gray;">, </span><span style="color: black;">df.Files<br />
</span><span style="color: blue;">FROM<br />
</span><span style="color: gray;">(</span><span style="color: blue;">SELECT </span><span style="color: magenta;">COUNT</span><span style="color: gray;">(*) </span><span style="color: blue;">AS </span><span style="color: black;">Cores </span><span style="color: blue;">FROM </span><span style="color: black;"><span style="color: #008000;">sys.dm_os_schedulers</span> </span><span style="color: blue;">WHERE </span><span style="color: black;">status </span><span style="color: blue;">= </span><span style="color: red;">'VISIBLE ONLINE'</span><span style="color: gray;">) </span><span style="color: blue;">AS </span><span style="color: black;">os</span><span style="color: gray;">,<br />
(</span><span style="color: blue;">SELECT </span><span style="color: magenta;">COUNT</span><span style="color: gray;">(*) </span><span style="color: blue;">AS </span><span style="color: black;">Files </span><span style="color: blue;">FROM </span><span style="color: black;"><span style="color: #008000;">tempdb.sys.database_files</span> </span><span style="color: blue;">WHERE </span><span style="color: black;">type_desc </span><span style="color: blue;">= </span><span style="color: red;">'ROWS'</span><span style="color: gray;">) </span><span style="color: blue;">AS </span><span style="color: black;">df</span><span style="color: gray;">;<br />
</span><span style="color: black;">GO</span></code></p>
<p>I simply took that query and wrapped it with <span style="text-decoration: underline;"><em>almost</em></span> the same code that I used at SQL University.  The difference allows me to show off two new tricks.  <img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" src="http://sqlvariant.com/wordpress/wp-content/uploads/2011/02/wlEmoticon-smile1.png" alt="Smile" /></p>
<ul>
<li>First, I separated out the part that grabs the list of servers from your Registered Servers to happen <em>before</em> the foreach loop.  I had received feedback from a reader that A) Having it there made it hard to read on my website, and B) it simplified the logic flow.  It also has the added benefits of performing faster when you’re running against hundreds of instances like me, and making it a little more clear how to swap it out when you want to use something besides Registered Servers to list your instances.  For more information on the different data sources that you can use for reading in a list of servers have a look here at <a href="http://sqlvariant.com/wordpress/index.php/2011/01/powershell-week-at-sql-university-post-5/">Post 5</a>.</li>
<li>Second I added this <span style="color: #ff4500;">$S</span><span style="color: #a9a9a9;">++</span><span style="color: #000000;">;</span> it is a little piece of code to enumerate the instances for you.  Last time I had written the results to a table and then read them out using DENSE_RANK but since we don’t have multiple results this time [and because I love showing off cool PowerShell code] I used this instead.</li>
</ul>
<pre class="PowerShellColorizedScript"><span style="color: #ff4500;">$ServerList</span> <span style="color: #a9a9a9;">=</span> <span style="color: #0000ff;">dir</span> <span style="color: #000080;">-recurse</span> <span style="color: #8a2be2;">SQLSERVER:\SQLRegistration\'Database Engine Server Group'\</span> <span style="color: #a9a9a9;">|</span> <span style="color: #0000ff;">where</span> <span style="color: #000000;">{</span><span style="color: #ff4500;">$_</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">Mode</span> <span style="color: #a9a9a9;">-ne</span> <span style="color: #8b0000;">"d"</span><span style="color: #000000;">}</span>            

<span style="color: #00008b;">foreach</span> <span style="color: #000000;">(</span><span style="color: #ff4500;">$RegisteredSQLs</span> <span style="color: #00008b;">in</span> <span style="color: #ff4500;">$ServerList</span> <span style="color: #000000;">)</span>
<span style="color: #000000;">{</span>
<span style="color: #ff4500;">$S</span><span style="color: #a9a9a9;">++</span><span style="color: #000000;">;</span>
<span style="color: #ff4500;">$dt</span><span style="color: #a9a9a9;">+=</span><span style="color: #0000ff;">invoke-sqlcmd2</span> <span style="color: #000080;">-ServerInstance</span> <span style="color: #ff4500;">$RegisteredSQLs</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">ServerName</span> <span style="color: #000080;">-database</span> <span style="color: #8a2be2;">master</span> <span style="color: #000080;">-Query</span> <span style="color: #8b0000;">"
    (SELECT COUNT(*) AS Cores FROM sys.dm_os_schedulers WHERE status = 'VISIBLE ONLINE') AS os,
    (SELECT COUNT(*) AS Files FROM tempdb.sys.database_files WHERE type_desc = 'ROWS') AS df"</span> <span style="color: #000080;">-As</span> <span style="color: #8b0000;">'DataTable'</span>
<span style="color: #000000;">}</span>            

<span style="color: #ff4500;">$MultipleResults</span> <span style="color: #a9a9a9;">=</span> <span style="color: #ff4500;">$dt</span> <span style="color: #a9a9a9;">|</span> <span style="color: #0000ff;">ConvertTo-Html</span> <span style="color: #000080;">-Property</span> <span style="color: #8a2be2;">Instance</span><span style="color: #a9a9a9;">,</span> <span style="color: #8a2be2;">Cores</span><span style="color: #a9a9a9;">,</span> <span style="color: #8a2be2;">Files</span> <span style="color: #a9a9a9;">|</span> <span style="color: #0000ff;">Out-String</span><span style="color: #000000;">;</span>            

<span style="color: #0000ff;">Send-MailMessage</span> <span style="color: #000080;">-To</span> <span style="color: #8a2be2;">paul@SQLskills.com</span> <span style="color: #000000;">`
</span> <span style="color: #000080;">-Subject</span> <span style="color: #8b0000;">"tempdb Survey Results"</span> <span style="color: #000000;">`
</span> <span style="color: #000080;">–From</span> <span style="color: #8a2be2;">YourEmailAddress@GoesHere.com</span> <span style="color: #000000;">`
</span> <span style="color: #000080;">-SmtpServer</span> <span style="color: #8a2be2;">YourSMTPServerGoesHere</span> <span style="color: #000000;">`
</span> <span style="color: #000080;">-Body</span> <span style="color: #ff4500;">$MultipleResults</span> <span style="color: #000080;">-BodyAsHtml</span></pre>
<p>Hopefully this will help you email query results to your heart&#8217;s content <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />   Big thanks to TJay Belt ( <a href="http://tjaybelt.blogspot.com/">blog</a> | <a href="http://twitter.com/tjaybelt">@TJayBelt</a> ) for pointing out this request on the <a href="http://twitter.com/#search?q=%23SQLHelp">#SQLHelp hotline</a> to me.  I&#8217;ve done this tons of times myself and I LOVE that anyone can walk up with a question and when people don&#8217;t have the answer they still do what they can to help them out right away.  I <em>less than three</em> community!!</p>
<blockquote><p>Please Note:</p>
<p>DO NOT SPAM Paul Randal! You should probably try emailing this to yourself a time or two before you decide to send it to him.</p>
<p>I’m using Chad Miller’s (<a href="http://sev17.com/">Blog</a>|<a href="http://www.twitter.com/cmille19">Twitter</a>) <a href="http://gallery.technet.microsoft.com/ScriptCenter/en-us/7985b7ef-ed89-4dfd-b02a-433cc4e30894"><strong>invoke-sqlcmd2 </strong></a>to output the results as a data table (you’ll need that).</p>
<p>Finally a friendly reminder that unlike SQL Server, PowerShell persists variables so if you run this multiple times you’ll want to clear out the $dt variable like this: <span style="color: #ff4500;">$dt</span><span style="color: #a9a9a9;">=</span><span style="color: #ff4500;">$null.</span></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://sqlvariant.com/wordpress/index.php/2011/02/emailing-tempdb-query-results-to-paul-randal-with-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell for Windows Admins &#8211; Code and Slides</title>
		<link>http://sqlvariant.com/wordpress/index.php/2010/06/powershell-for-windows-admins-code-and-slides/</link>
		<comments>http://sqlvariant.com/wordpress/index.php/2010/06/powershell-for-windows-admins-code-and-slides/#comments</comments>
		<pubDate>Fri, 18 Jun 2010 15:23:10 +0000</pubDate>
		<dc:creator>Aaron Nelson</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Training Event]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Slide Deck]]></category>

		<guid isPermaLink="false">http://sqlvariant.com/wordpress/?p=1097</guid>
		<description><![CDATA[Two weeks back I had the opportunity to present a session on PowerShell Windows Admin Commands at the Atlanta TechStravaganza.  I was a little worried about the presentation because I had never presented to a crowd of system administrators before.  Luckily I pulled it off and believe the standing room only crowd learned a lot and discovered ways to make PowerShell relevant to their work.  They did stump me with a question about opening ports but luckily Mark Schill ( blog &#124; twitter ) was able to provide the correct answer for us all.  Thanks to everyone who took time out of their Friday to come by and see it.  I got a lot of great comments from people in the hallway after my session.  Some of them really liked the different approach I took to presenting it.  As promised here are all of the Sildes and Scritps that I used during the session. Oh and thanks to all the sponsors!]]></description>
			<content:encoded><![CDATA[<p>Two weeks back I had the opportunity to present a session on PowerShell Windows Admin Commands at the Atlanta TechStravaganza.  I was a little worried about the presentation because I had never presented to a crowd of system administrators before.  Luckily I pulled it off and believe the standing room only crowd learned a lot and discovered ways to make PowerShell relevant to their work.  They did stump me with a question about opening ports but luckily Mark Schill ( <a href="http://www.cmschill.net/StringTheory/">blog</a> | <a href="http://twitter.com/meson3902">twitter</a> ) was able to provide the correct answer for us all. </p>
<p>Thanks to everyone who took time out of their Friday to come by and see it.  I got a lot of great comments from people in the hallway after my session.  Some of them really liked the different approach I took to presenting it.  As promised here are all of the <a href="http://sqlvariant.com/BlogSupport/SlideDecks/PowerShellWindowsAdminCommands.pptx">Sildes</a> and <a href="http://sqlvariant.com/BlogSupport/ATL-TechStravaganzaScripts.zip">Scritps</a> that I used during the session.</p>
<p><a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/06/IMG00287201006041057.jpg"><img style="display: inline; border-width: 0px;" title="IMG00287-20100604-1057" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/06/IMG00287201006041057_thumb.jpg" border="0" alt="IMG00287-20100604-1057" width="480" height="361" /></a></p>
<p>Oh and thanks to all the sponsors!</p>
<p><a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/06/image.png"><img style="display: inline; border: 0px;" title="image" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/06/image_thumb.png" border="0" alt="image" width="238" height="352" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://sqlvariant.com/wordpress/index.php/2010/06/powershell-for-windows-admins-code-and-slides/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell Week at SQL University – Post 3: Providers, PSDrive</title>
		<link>http://sqlvariant.com/wordpress/index.php/2010/05/powershell-week-at-sql-university-post-3/</link>
		<comments>http://sqlvariant.com/wordpress/index.php/2010/05/powershell-week-at-sql-university-post-3/#comments</comments>
		<pubDate>Thu, 20 May 2010 17:23:34 +0000</pubDate>
		<dc:creator>Aaron Nelson</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Training Event]]></category>
		<category><![CDATA[cmdlets]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[snapins]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL University]]></category>
		<category><![CDATA[Syndicated]]></category>

		<guid isPermaLink="false">http://sqlvariant.com/wordpress/?p=1052</guid>
		<description><![CDATA[Providers What are Providers? Providers in PowerShell are a hierarchical namespace way flattening out an infrastructure to make it accessible and traverse-able just like a directory structure hard drive. Why do you need them? Well you quite possibly may not ‘need’ them per-say but they sure do make things easier to work with from time to time. In case you don’t already know, you can traverse your SQL Server [2008] as if it were just another drive in either SSMS 2008 or in the PowerShell ISE if you add the Provider Snapin. To make sure that you have this snapin installed on your machine see yesterday’s post but this time we are going to add the ProviderSnapin instead of the CmdletSnapin. To do that just run add-pssnapin SqlServerProviderSnapin100 and poof you can traverse SQL Server. Let’s take a look at what we might see. Run get-psdrive and you should see a list of drives including SQL Server. Now if you have more that one instance you will be able to access all of them through this one “SQLServer:\” PSDrive that you now have. In a lot cases what we find inside of these drives will be similar to what we see in the Object Explorer view in SSMS but almost always have something extra too. Let’s take a look at that here by changing directories down to our databases cd SQLSERVER:\sql\YourComputerName\YourInstanceName\ cd SQLSERVER:\sql\WIN7\KILIMANJARO\ Now let’s go ahead and run the good old “Dir” command and we should get back something like this dir As I mentioned before, we got back more than we see if we expand our SQL Server node in the Object Explorer window of SSMS, now if we CD to Databases and do another dir we will see not just more than what we see in SSMS, we see what at first glace to a SQL person is just garbage (but it’s not). cd Databases dir What you’re seeing here is the Methods and Properties of the databases in your instance. What are Methods and Properties? Well if you’re like I was 6 months ago you have no idea what Methods and Properties are. Methods are the Verbs of what you can do to your database (Create, Rename, Drop, Shrink) and Properties and the Adjectives that describe your database (Collation, CreateDate, Compatibility Level, Owner, AutoShrink Enabled). To get just the list of the names of your databases you’re going to have to run this: dir &#124; select-object name Ok so now we can see a list of databases that our Provider made available to us. So what? Well I’m going to dive a little deeper tomorrow but for now let’s just go with one final example on scripting out tables (more on that here). Run this: cd AdventureWorks\Tables Then this: foreach ($tbl in dir ) { $k="C:\Temp\" + $($tbl.name) + "_table.SQL" $tbl.Script() &#62; $k } I really hope you have temp directory on your C:\ drive. If so go have a look what’s there now So is that it? Almost. While SQL Server 2008 only comes with one provider and it&#8217;s for the Relational Engine a few people have taken it upon themselves to create their own Provider for things like Analysis Services, Reporting Services, and event BizTalk up on the codeplex site. I can say that I have tried the Analysis Services project and it does work. del.icio.us Tags: cmdlets,functions,PowerShell,snapins,SQL Server 2008,SQL University]]></description>
			<content:encoded><![CDATA[<h4>Providers</h4>
<p>What are Providers?  Providers in PowerShell are a <span style="text-decoration: line-through;">hierarchical namespace</span> way flattening out an infrastructure to make it accessible and traverse-able just like a <span style="text-decoration: line-through;">directory structure</span> hard drive.  Why do you need them?  Well you quite possibly may not ‘<em>need</em>’ them per-say but they sure do make things easier to work with from time to time.  In case you don’t already know, you can traverse your SQL Server [2008] as if it were just another drive in either SSMS 2008 or in the PowerShell ISE if you add the Provider Snapin.</p>
<p>To make sure that you have this snapin installed on your machine see <a href="http://sqlvariant.com/wordpress/index.php/2010/05/powershell-week-at-sql-university-post-2/">yesterday’s post</a> but this time we are going to add the ProviderSnapin instead of the CmdletSnapin.</p>
<p><a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image19.png"><img title="image" style="display: inline; border: 0px;" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image_thumb18.png" border="0" alt="image" width="654" height="112" /></a></p>
<p>To do that just run</p>
<pre class="PowerShellColorizedScript"><span style="color: #0000ff;">add-pssnapin</span> <span style="color: #8a2be2;">SqlServerProviderSnapin100</span></pre>
<p>and poof you can traverse SQL Server.  Let’s take a look at what we might see.  Run</p>
<pre class="PowerShellColorizedScript"><span style="color: #0000ff;">get-psdrive</span></pre>
<p>and you should see a list of drives including SQL Server.  Now if you have more that one instance you will be able to access all of them through this one “SQLServer:\” PSDrive that you now have.  In a lot cases what we find inside of these drives will be similar to what we see in the Object Explorer view in SSMS but almost always have something extra too.  Let’s take a look at that here by changing directories down to our databases</p>
<p><b>cd SQLSERVER:\sql\YourComputerName\YourInstanceName\</b></p>
<pre class="PowerShellColorizedScript"><span style="color: #0000ff;">cd</span> <span style="color: #8a2be2;">SQLSERVER:\sql\WIN7\KILIMANJARO\</span></pre>
<p>Now let’s go ahead and run the good old “Dir” command and we should get back something like this</p>
<pre class="PowerShellColorizedScript"><span style="color: #0000ff;">dir</span></pre>
<p><a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image20.png"><img title="image" style="display: inline; border: 0px;" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image_thumb19.png" border="0" alt="image" width="398" height="310" /></a></p>
<p>As I mentioned before, we got back more than we see if we expand our SQL Server node in the Object Explorer window of SSMS, now if we CD to Databases and do another dir we will see not just more than what we see in SSMS, we see what at first glace to a SQL person is just garbage (but it’s not).</p>
<pre class="PowerShellColorizedScript"><span style="color: #0000ff;">cd</span> <span style="color: #8a2be2;">Databases</span>
<span style="color: #0000ff;">dir</span></pre>
<p><a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image21.png"><img title="image" style="display: inline; border: 0px;" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image_thumb20.png" border="0" alt="image" width="651" height="230" /></a></p>
<p>What you’re seeing here is the <strong>Methods</strong> and <strong>Properties</strong> of the databases in your instance.  What are <a href="http://msdn.microsoft.com/en-us/library/ms173114(VS.80).aspx">Methods</a> and <a href="http://msdn.microsoft.com/en-us/library/x9fsa0sw.aspx">Properties</a>?  Well if you’re like I was 6 months ago you have no idea what Methods and Properties are.  Methods are the Verbs of what you can do to your database (Create, Rename, Drop, <span style="text-decoration: line-through;">Shrink</span>) and Properties and the Adjectives that describe your database (Collation, CreateDate, Compatibility Level, Owner, <span style="text-decoration: line-through;">AutoShrink Enabled</span>).  To get <span style="text-decoration: underline;">just</span> the list of the names of your databases you’re going to have to run this:</p>
<pre class="PowerShellColorizedScript"><span style="color: #0000ff;">dir</span> <span style="color: #a9a9a9;">|</span> <span style="color: #0000ff;">select-object</span> <span style="color: #8a2be2;">name</span></pre>
<p><a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image22.png"><img title="image" style="display: inline; border: 0px;" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image_thumb21.png" border="0" alt="image" width="320" height="197" /></a></p>
<p>Ok so now we can see a list of databases that our Provider made available to us.   So what?  Well I’m going to dive a little deeper tomorrow but for now let’s just go with one final example on scripting out tables (more on that <a href="http://bit.ly/96nmwE">here</a>).  Run this: <span style="color: #0000ff;">cd</span> <span style="color: #8a2be2;">AdventureWorks\Tables </span>Then this:</p>
<pre class="PowerShellColorizedScript"><span style="color: #00008b;">foreach</span> <span style="color: #000000;">(</span><span style="color: #ff4500;">$tbl</span> <span style="color: #00008b;">in</span> <span style="color: #0000ff;">dir</span> <span style="color: #000000;">)</span>

<span style="color: #000000;">{</span>
<span style="color: #ff4500;">$k</span><span style="color: #a9a9a9;">=</span><span style="color: #8b0000;">"C:\Temp\"</span> <span style="color: #a9a9a9;">+</span> <span style="color: #000000;">$(</span><span style="color: #ff4500;">$tbl</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">name</span><span style="color: #000000;">)</span> <span style="color: #a9a9a9;">+</span> <span style="color: #8b0000;">"_table.SQL"</span>
<span style="color: #ff4500;">$tbl</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">Script</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span> <span style="color: #a9a9a9;">&gt;</span> <span style="color: #ff4500;">$k</span>
<span style="color: #000000;">}</span></pre>
<p>I really hope you have temp directory on your C:\ drive.  If so go have a look what’s there now <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>So is that it?  Almost.  While SQL Server 2008 only comes with one provider and it&#8217;s for the Relational Engine a few people have taken it upon themselves to create their own Provider for things like <a href="http://powerssas.codeplex.com/">Analysis Services</a>,  <a href="http://ssrsposh.codeplex.com/">Reporting Services</a>, and event <a href="http://psbiztalk.codeplex.com/">BizTalk</a> up on the codeplex site.  I can say that I have tried the Analysis Services project and it does work.</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:11691a5d-8454-40f5-a2a3-5e207cd3c246">del.icio.us Tags: <a href="http://del.icio.us/popular/cmdlets" rel="tag">cmdlets</a>,<a href="http://del.icio.us/popular/functions" rel="tag">functions</a>,<a href="http://del.icio.us/popular/PowerShell" rel="tag">PowerShell</a>,<a href="http://del.icio.us/popular/snapins" rel="tag">snapins</a>,<a href="http://del.icio.us/popular/SQL+Server+2008" rel="tag">SQL Server 2008</a>,<a href="http://del.icio.us/popular/SQL+University" rel="tag">SQL University</a></div>
]]></content:encoded>
			<wfw:commentRss>http://sqlvariant.com/wordpress/index.php/2010/05/powershell-week-at-sql-university-post-3/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>PowerShell Week at SQL University &#8211; Post 2</title>
		<link>http://sqlvariant.com/wordpress/index.php/2010/05/powershell-week-at-sql-university-post-2/</link>
		<comments>http://sqlvariant.com/wordpress/index.php/2010/05/powershell-week-at-sql-university-post-2/#comments</comments>
		<pubDate>Wed, 19 May 2010 13:14:16 +0000</pubDate>
		<dc:creator>Aaron Nelson</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Training Event]]></category>
		<category><![CDATA[cmdlets]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[snapins]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL University]]></category>
		<category><![CDATA[Syndicated]]></category>

		<guid isPermaLink="false">http://sqlvariant.com/wordpress/?p=1038</guid>
		<description><![CDATA[Cmdlets, Functions and Snapins So far we’ve learned how to open up PowerShell and add on to it with some modules; then we learned how to create a variable and populate it with anything from some numbers to an entire table. Today we’re going to quickly look at another way of expanding PowerShell with something called a snapin so that we can get to some cmdlets. First, what are cmdlets? Cmdlets are similar to DOS commands but have some noteworthy differences. In SQL Server terms you might think of cmdlets as the System Stored Procedures of PowerShell and think of functions as the regular user defined Stored Procedures of PowerShell. Cmdlets and functions accept parameters just like stored procedures do. Just like stored procedures you can even define default values for these parameters in case the user doesn’t have one to pass in. Unlike stored procedures though there is actually a drive that you can go to and see all of your functions. Just run this and you’ll see what I mean dir function: Snapins are akin to finished product code. They were created for PowerShell 1.0 and were succeeded in PowerShell 2.0 by modules&#8211; which are more like the manifest list for deploying a bunch of SSIS packages. If you have SSMS 2008 installed you’ve got yourself two extra snapins already. And if you have Idera’s SQL Diagnostic Manager installed you may be in for a real surprise when you retrieve your list of snapins. Run this command to see all of the extra snapins that are available to you: get-pssnapin –registered At the very least you should see this: If you don’t see those two you’ll need to install SSMS 2008. If you don’t have a copy of that handy you can get the free version of it here. The SqlServerCmdletSnapin100 snapin give us the 5 cmdlets that come with SQL Server 2008 and today we’re going to focus on Invoke-SQLcmd which basically just calls out to good old sqlcmd. To load this just run: add-pssnapin SqlServerCmdletSnapin100 From there we can do a quick query like this: invoke-sqlcmd -query &#8220;sp_databases&#8221; -database master -serverinstance YourServerName\YourInstanceName &#124; format-table invoke-sqlcmd -query "sp_databases" -database master -serverinstance WIN7\Kilimanjaro &#124; format-table Now the reason that I brought up functions is because they override cmdlets and that’s really important to know. If you run this command get-command invoke-sqlcmd you will only see one thing returned for invoke-sqlcmd. However if we create a new function like: function invoke-sqlcmd { get-date } You end up overriding the Invoke-SQLcmd with your new function. Give it a try, run just this invoke-sqlcmd and you should end up seeing something like this: So how do you know when you’ve done something like that? Just run get-command invoke-sqlcmd again and this time you will see this: I realize that we kind of rushed through that info but thankfully there is only one more piece to the basics before we can get on to code that you can use on a daily basis del.icio.us Tags: SQL Server 2008,PowerShell,SQL University,snapins,cmdlets,functions]]></description>
			<content:encoded><![CDATA[<h3>Cmdlets, Functions and Snapins</h3>
<p>So far we’ve learned how to open up PowerShell and add on to it with some <a href="http://sqlvariant.com/wordpress/index.php/2010/05/powershell-week-at-sql-university-post-0/">modules</a>; then we learned how to create a <a href="http://sqlvariant.com/wordpress/index.php/2010/05/powershell-week-at-sql-university-post-1/">variable</a> and populate it with anything from some numbers to an entire table.  Today we’re going to quickly look at another way of expanding PowerShell with something called a <span style="color: #0000ff;">snapin</span> so that we can get to some cmdlets.</p>
<p>First, what are <span style="color: #0000ff;">cmdlets</span>?  Cmdlets are similar to DOS commands but have some noteworthy differences.  In SQL Server terms you might think of <span style="color: #0000ff;">cmdlets</span> as the System Stored Procedures of PowerShell and think of <span style="color: #0000ff;">functions</span> as the regular user defined Stored Procedures of PowerShell.</p>
<p><span style="color: #0000ff;">Cmdlets</span> and <span style="color: #0000ff;">functions</span> accept parameters just like stored procedures do.  Just like stored procedures you can even define default values for these parameters in case the user doesn’t have one to pass in.  Unlike stored procedures though there is actually a drive that you can go to and see all of your functions.  Just run this and you’ll see what I mean <span style="color: #0000ff;">dir</span> <span style="color: #8a2be2;">function:</span></p>
<p><span style="color: #0000ff;">Snapins</span> are akin to finished product code. They were created for PowerShell 1.0 and were succeeded in PowerShell 2.0 by modules&#8211; which are more like the manifest list for deploying a bunch of SSIS packages.  If you have SSMS 2008 installed you’ve got yourself two extra <span style="color: #0000ff;">snapins</span> already.  And if you have Idera’s SQL Diagnostic Manager installed you may be in for a real surprise when you retrieve your list of snapins.  Run this command to see all of the extra <span style="color: #0000ff;">snapins</span> that are available to you:</p>
<p><span style="color: #0000ff;">get-pssnapin</span> –<span style="color: #000080;">registered </span></p>
<p>At the very least you should see this:</p>
<p><a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image15.png"><img title="image" style="display: inline; border: 0px;" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image_thumb14.png" border="0" alt="image" width="583" height="98" /></a></p>
<p>If you don’t see those two you’ll need to install SSMS 2008.  If you don’t have a copy of that handy you can get the free version of it <a href="http://www.microsoft.com/express/Database/">here</a>.  The SqlServerCmdletSnapin100 snapin give us the 5 cmdlets that come with SQL Server 2008 and today we’re going to focus on <span style="color: #0000ff;">Invoke-SQLcmd</span> which basically just calls out to good old sqlcmd.  To load this just run:</p>
<pre class="PowerShellColorizedScript"><span style="color: #0000ff;">add-pssnapin</span> <span style="color: #8a2be2;">SqlServerCmdletSnapin100</span></pre>
<p>From there we can do a quick query like this:</p>
<p><b>invoke-sqlcmd -query &#8220;sp_databases&#8221; -database master -serverinstance YourServerName\YourInstanceName | format-table</b></p>
<pre class="PowerShellColorizedScript"><span style="color: #0000ff;">invoke-sqlcmd</span> <span style="color: #000080;">-query</span> <span style="color: #8b0000;">"sp_databases"</span> <span style="color: #000080;">-database</span> <span style="color: #8a2be2;">master</span> <span style="color: #000080;">-serverinstance</span> <span style="color: #8a2be2;">WIN7\Kilimanjaro</span> <span style="color: #a9a9a9;">|</span> <span style="color: #0000ff;">format-table</span></pre>
<pre class="PowerShellColorizedScript"><a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image16.png"><img title="image" style="display: inline; border: 0px;" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image_thumb15.png" border="0" alt="image" width="610" height="221" /></a></pre>
<p>Now the reason that I brought up functions is because they override cmdlets and that’s really important to know.  If you run this command <span style="color: #0000ff;">get-command</span> <span style="color: #8a2be2;">invoke-sqlcmd</span> you will only see one thing returned for <span style="color: #0000ff;">invoke-sqlcmd</span>.  However if we create a new function like:</p>
<pre class="PowerShellColorizedScript"><span style="color: #00008b;">function</span> <span style="color: #8a2be2;">invoke-sqlcmd</span> <span style="color: #000000;">{</span> <span style="color: #0000ff;">get-date</span> <span style="color: #000000;">}</span></pre>
<p>You end up overriding the <span style="color: #0000ff;">Invoke-SQLcmd</span> with your new function.  Give it a try, run just this <span style="color: #0000ff;">invoke-sqlcmd</span> and you should end up seeing something like this:</p>
<p><a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image17.png"><img title="image" style="display: inline; border: 0px;" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image_thumb16.png" border="0" alt="image" width="249" height="54" /></a></p>
<p>So how do you know when you’ve done something like that?  Just run <span style="color: #0000ff;">get-command</span> <span style="color: #8a2be2;">invoke-sqlcmd</span> again and this time you will see this:</p>
<p><a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image18.png"><img title="image" style="display: inline; border: 0px;" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image_thumb17.png" border="0" alt="image" width="497" height="92" /></a></p>
<p>I realize that we kind of rushed through that info but thankfully there is only one more piece to the basics before we can get on to code that you can use on a daily basis <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:3e617843-6dab-4bc5-9b32-a16e505c34ac">del.icio.us Tags: <a href="http://del.icio.us/popular/SQL+Server+2008" rel="tag">SQL Server 2008</a>,<a href="http://del.icio.us/popular/PowerShell" rel="tag">PowerShell</a>,<a href="http://del.icio.us/popular/SQL+University" rel="tag">SQL University</a>,<a href="http://del.icio.us/popular/snapins" rel="tag">snapins</a>,<a href="http://del.icio.us/popular/cmdlets" rel="tag">cmdlets</a>,<a href="http://del.icio.us/popular/functions" rel="tag">functions</a></div>
]]></content:encoded>
			<wfw:commentRss>http://sqlvariant.com/wordpress/index.php/2010/05/powershell-week-at-sql-university-post-2/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>PowerShell Week at SQL University – Post 1</title>
		<link>http://sqlvariant.com/wordpress/index.php/2010/05/powershell-week-at-sql-university-post-1/</link>
		<comments>http://sqlvariant.com/wordpress/index.php/2010/05/powershell-week-at-sql-university-post-1/#comments</comments>
		<pubDate>Tue, 18 May 2010 18:49:03 +0000</pubDate>
		<dc:creator>Aaron Nelson</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Training Event]]></category>
		<category><![CDATA[Execution Policy]]></category>
		<category><![CDATA[Modules]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL University]]></category>
		<category><![CDATA[SQLPSX]]></category>
		<category><![CDATA[Syndicated]]></category>

		<guid isPermaLink="false">http://sqlvariant.com/wordpress/?p=1025</guid>
		<description><![CDATA[Getting Started With PowerShell Variables Yesterday we laid the ground work for PowerShell Week.  Today we will learn about Variables in PowerShell. You will notice that PowerShell variables work very differently from SQL Server variables. The evolution of variables in SQL Server is pretty straight forward. In SQL Server 2000 you had to DECLARE a variable as a specific type in one statement and then SET the value of the variable in another statement, like this: DECLARE @SQLvariable VARCHAR(12) SET @SQLvariable = &#8216;OldFeature&#8217;. By the time SQL 2008 hit the streets we could DECLARE and SET a variable in one statement like this: DECLARE @SQLvariable VARCHAR(12) = &#8216;NewFeature&#8217; . PowerShell evolves variables to the next logical step.  You no longer need to declare or type your variable. Instead PowerShell uses the value of the variable to infer it&#8217;s type. If a variable does not alreayd exist PowerShell simply creates it for you.  In PowerShell our statement looks like this: $SQLvariable = &#8216;NewFeature&#8217;. (Beginer tip: $ identifies variables in PowerShell just like @ identifies them in SQL Server.) Since it doesn’t work in SQL let’s try it in PowerShell: $SQLvariable = &#8216;NewFeature&#8217;.  OK so we loaded data into a variable, ‘big deal’ right?  How do we know that we actually loaded it and more importantly what datatype is it?  Well in PowerShell you can simply call the variable to get its value. (Another beginer tip: you don&#8217;t need to use a keyword like SELECT for this, just the variable name: $SQLvariable.)  What if you just want to determine the datatype?  All you have to do is tack on the .GetType() Method: $SQLvariable.GetType(). $SQLvariable = 'NewFeature' $SQLvariable $SQLvariable.GetType() When you run this here’s what your result will be: As I alluded to earlier, another feature of PowerShell is that it remembers your variables for you, even between executions.  Basically as long as you don&#8217;t end your session the variable, it’s datatype, and its value will persist.  You will see later than you can also set a variable in one script and consume it in another. Let’s try this again with a new variable and set it to a different value: $PoShvariable = 123 $PoShvariable $PoShvariable.GetType() What happens if once the datatype is set we try to set it to a different, incompatible datatype?  It’s going to explode right?  Nope, you’ll have to throw something more difficult than that at it.  Give this a try: $PoShvariable.GetType() $PoShvariable = 'NewFeature' $PoShvariable $PoShvariable.GetType()      Since PowerShell relies on .NET a variable could be any datatype in .NET so if you’re sitting inside the AdventureWorks database you can see for yourself, just run this: $MyTable = get-item TABLESProduction.TransactionHistory $MyTable.GetType() $MyStoredProc = get-item StoredProceduresHumanResources.uspUpdateEmployeePersonalInfo $MyStoredProc.GetType() Now earlier I mentioned that PowerShell keeps track of and remembers the variables that you previously declared.  So how do you see what variables are already there?  Just run this command and you can see every variable you have running in the session, even the internal ones. Variable In the list of items that get returned you’ll see one called Error that holds the last error message that occurred in your session.  This handy feature can help you when you have to debug your own work. Is that all there is to know about variables in PowerShell?  Not hardly, but I think that’s a good stopping point for this post.  More on variables later. del.icio.us Tags: SQL Server 2008,PowerShell,SQL University,Modules,Execution Policy,SQLPSX]]></description>
			<content:encoded><![CDATA[<h4>Getting Started With PowerShell Variables</h4>
<p>Yesterday we laid the <a href="http://sqlvariant.com/wordpress/index.php/2010/05/powershell-week-at-sql-university-post-0/">ground work</a> for PowerShell Week.  Today we will learn about <strong>Variables </strong>in PowerShell. You will notice that PowerShell variables work very differently from SQL Server variables.</p>
<p>The evolution of variables in SQL Server is pretty straight forward. In SQL Server 2000 you had to DECLARE a variable as a specific type in one statement and then SET the value of the variable in another statement, like this: <span style="font-family: &amp;amp;amp; color: blue; font-size: 10pt; mso-no-proof: yes;">DECLARE</span><span style="font-family: &amp;amp;amp; font-size: 10pt; mso-no-proof: yes;"> @SQLvariable <span style="color: blue;">VARCHAR</span><span style="color: gray;">(</span>12<span style="color: gray;">)</span> </span><span style="line-height: 115%; font-family: &amp;amp;amp; color: blue; font-size: 10pt; mso-fareast-font-family: calibri; mso-fareast-theme-font: minor-latin; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa; mso-no-proof: yes;">SET</span><span style="line-height: 115%; font-family: &amp;amp;amp; font-size: 10pt; mso-fareast-font-family: calibri; mso-fareast-theme-font: minor-latin; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa; mso-no-proof: yes;"> @SQLvariable <span style="color: gray;">=</span> <span style="color: red;">&#8216;OldFeature&#8217;</span></span>. By the time SQL 2008 hit the streets we could DECLARE and SET a variable in one statement like this: <span style="line-height: 115%; font-family: &amp;amp;amp; color: blue; font-size: 10pt; mso-fareast-font-family: calibri; mso-fareast-theme-font: minor-latin; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa; mso-no-proof: yes;">DECLARE</span><span style="line-height: 115%; font-family: &amp;amp;amp; font-size: 10pt; mso-fareast-font-family: calibri; mso-fareast-theme-font: minor-latin; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa; mso-no-proof: yes;"> @SQLvariable <span style="color: blue;">VARCHAR</span><span style="color: gray;">(</span>12<span style="color: gray;">)</span> <span style="color: gray;">=</span> <span style="color: red;">&#8216;NewFeature&#8217;</span></span> . PowerShell evolves variables to the next logical step.  You no longer need to declare or type your variable. Instead PowerShell uses the value of the variable to infer it&#8217;s type. If a variable does not alreayd exist PowerShell simply creates it for you.  In PowerShell our statement looks like this: <span style="line-height: 115%; font-family: &amp;amp;amp; font-size: 10pt; mso-no-proof: yes;">$SQLvariable<span style="color: blue;"> </span><span style="color: gray;">=</span> <span style="color: red;">&#8216;NewFeature&#8217;</span></span>. (Beginer tip: $ identifies variables in PowerShell just like @ identifies them in SQL Server.)</p>
<p>Since it doesn’t work in SQL let’s try it in PowerShell: <span style="color: #ff4500;">$SQLvariable</span> <span style="color: #a9a9a9;">=</span> <span style="color: #8b0000;">&#8216;NewFeature&#8217;.  </span>OK so we loaded data into a variable, ‘big deal’ right?  How do we know that we actually loaded it and more importantly what datatype is it?  Well in PowerShell you can simply call the variable to get its value. (Another beginer tip: you don&#8217;t need to use a keyword like SELECT for this, just the variable name: <span style="color: #ff4500;">$SQLvariable<span style="color: #000000;">.</span><span style="color: #000000;">)</span>  </span>What if you just want to determine the datatype?  All you have to do is tack on the .GetType() Method: <span style="color: #ff4500;">$SQLvariable</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">GetType</span><span style="color: #000000;">(</span><span style="color: #000000;">).</span></p>
<pre class="PowerShellColorizedScript"><span style="color: #ff4500;">$SQLvariable</span> <span style="color: #a9a9a9;">=</span> <span style="color: #8b0000;">'NewFeature'</span>
<span style="color: #ff4500;">$SQLvariable</span>
<span style="color: #ff4500;">$SQLvariable</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">GetType</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span></pre>
<p>When you run this here’s what your result will be:</p>
<pre class="PowerShellColorizedScript"><a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image11.png"><img style="display: inline; border: 0px;" title="image" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image_thumb10.png" border="0" alt="image" width="383" height="146" /></a></pre>
<p class="PowerShellColorizedScript">As I alluded to earlier, another feature of PowerShell is that it remembers your variables for you, even between executions.  Basically as long as you don&#8217;t end your session the variable, it’s datatype, and its value will persist.  You will see later than you can also set a variable in one script and consume it in another.</p>
<p class="PowerShellColorizedScript">Let’s try this again with a new variable and set it to a different value:</p>
<pre class="PowerShellColorizedScript"><span style="color: #ff4500;">$PoShvariable</span> <span style="color: #a9a9a9;">=</span> <span style="color: #800080;">123</span>
<span style="color: #ff4500;">$PoShvariable</span>
<span style="color: #ff4500;">$PoShvariable</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">GetType</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span></pre>
<p><a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image12.png"><img style="display: inline; border: 0px;" title="image" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image_thumb11.png" border="0" alt="image" width="349" height="155" /></a></p>
<p>What happens if once the datatype is set we try to set it to a different, incompatible datatype?  It’s going to explode right?  Nope, you’ll have to throw something more difficult than that at it.  Give this a try:</p>
<pre class="PowerShellColorizedScript"><span style="color: #ff4500;">$PoShvariable</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">GetType</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>
<span style="color: #ff4500;">$PoShvariable</span> <span style="color: #a9a9a9;">=</span> <span style="color: #8b0000;">'NewFeature'</span>
<span style="color: #ff4500;">$PoShvariable</span>
<span style="color: #ff4500;">$PoShvariable</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">GetType</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span></pre>
<p><span style="font-family: Courier New;"> </span></p>
<p> <a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image13.png"><img style="display: inline; border: 0px;" title="image" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image_thumb12.png" border="0" alt="image" width="372" height="177" /></a> </p>
<p>Since PowerShell relies on .NET a variable could be any datatype in .NET so if you’re sitting inside the AdventureWorks database you can see for yourself, just run this:</p>
<pre class="PowerShellColorizedScript"><span style="color: #ff4500;">$MyTable</span> <span style="color: #a9a9a9;">=</span> <span style="color: #0000ff;">get-item</span> <span style="color: #8a2be2;">TABLESProduction.TransactionHistory</span>
<span style="color: #ff4500;">$MyTable</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">GetType</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>            

<span style="color: #ff4500;">$MyStoredProc</span> <span style="color: #a9a9a9;">=</span> <span style="color: #0000ff;">get-item</span> <span style="color: #8a2be2;">StoredProceduresHumanResources.uspUpdateEmployeePersonalInfo</span>
<span style="color: #ff4500;">$MyStoredProc</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">GetType</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span></pre>
<pre class="PowerShellColorizedScript"><a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image14.png"><img style="display: inline; border: 0px;" title="image" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image_thumb13.png" border="0" alt="image" width="636" height="154" /></a></pre>
<p>Now earlier I mentioned that PowerShell keeps track of and remembers the variables that you previously declared.  So how do you see what variables are already there?  Just run this command and you can see every variable you have running in the session, even the internal ones.</p>
<pre class="PowerShellColorizedScript"><span style="color: #0000ff;">Variable</span></pre>
<p>In the list of items that get returned you’ll see one called Error that holds the last error message that occurred in your session.  This handy feature can help you when you have to debug your own work.</p>
<p>Is that all there is to know about variables in PowerShell?  Not hardly, but I think that’s a good stopping point for this post.  More on variables later.</p>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:e988a49f-e64e-4515-bbf2-cfdb576a0ff5" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">del.icio.us Tags: <a rel="tag" href="http://del.icio.us/popular/SQL+Server+2008">SQL Server 2008</a>,<a rel="tag" href="http://del.icio.us/popular/PowerShell">PowerShell</a>,<a rel="tag" href="http://del.icio.us/popular/SQL+University">SQL University</a>,<a rel="tag" href="http://del.icio.us/popular/Modules">Modules</a>,<a rel="tag" href="http://del.icio.us/popular/Execution+Policy">Execution Policy</a>,<a rel="tag" href="http://del.icio.us/popular/SQLPSX">SQLPSX</a></div>
]]></content:encoded>
			<wfw:commentRss>http://sqlvariant.com/wordpress/index.php/2010/05/powershell-week-at-sql-university-post-1/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>PowerShell Week at SQL University &#8211; Post 0</title>
		<link>http://sqlvariant.com/wordpress/index.php/2010/05/powershell-week-at-sql-university-post-0/</link>
		<comments>http://sqlvariant.com/wordpress/index.php/2010/05/powershell-week-at-sql-university-post-0/#comments</comments>
		<pubDate>Mon, 17 May 2010 14:55:06 +0000</pubDate>
		<dc:creator>Aaron Nelson</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Training Event]]></category>
		<category><![CDATA[Execution Policy]]></category>
		<category><![CDATA[Free Training]]></category>
		<category><![CDATA[Modules]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL University]]></category>
		<category><![CDATA[SQLPSX]]></category>
		<category><![CDATA[Syndicated]]></category>

		<guid isPermaLink="false">http://sqlvariant.com/wordpress/?p=1007</guid>
		<description><![CDATA[Welcome to PowerShell Week at SQL University. For regulars at SQLvariant, SQL University is something Jorge Segarra organized to get industry experts together to create learning courses around SQL Server. These learning courses are in one week segments that focus on a specific area. When I began blogging about PowerShell there were some complications based on your operating system. There were so many people blogging about these issues that I didn’t address it initially. Since this is an introductory course I decided to go ahead and spin up a brand new Windows 7 VM so that I can walk you through these small but vital details. If you don’t have Windows 7 this would be a great time to upgrade. If you can&#8217;t upgrade then download PowerShell for you operating system from this link. Now, onto getting started: Disclaimer: PowerShell opens in a protected state as a security measure. To enjoy the full power of PowerShell (and run scripts you downloaded off of the internet) you need to run without these safeguards. In today&#8217;s lesson we are simply launching PowerShell and priming it for the scripts and work we will interact with in the next several lessons. To get started with PowerShell just click the Start button and type in ISE to locate the Integrated Script Editor in your program listing. Right click and launch PowerShell in Run as Adminsitrator mode: Enter Get-ExecutionPolicy as a command. If you haven’t used PowerShell yet you will most likely see that the Execution Policy is set to “Restricted”. You’ll need to run the command Set-ExecutionPolicy RemoteSigned to be able to run the scripts and follow along with the lesson. You’ll also get a popup that you’ll have to say yes to. Your output should look very non-informative like this: Now that we have that set let’s go to SQLPSX.CodePlex.com and and download the SQLPSX project. It’s currently in version 2.2.1 and consists of 9 modules containing 133 advanced functions, only 2 cmdlets and 7 scripts. It’s for working with ADO.NET, SMO, SQL Agent, RMO, SSIS, SQL script files and using the PowerShell ISE as a SQL query tool: NOTE: Update at bottom with workaround: During the installation we will run it without modifying the profile (just yet). Once you’ve installed it successfully you should now have a WindowsPowerShell directory under your My Documents if you didn’t have one already (which is really important): After it’s installed we should be able to open up the ISE again and run this command : Get-Module -ListAvailable And finally we’re going to get to the step where we load something up. Run import-module SQLServer to load up the main SQL Server module. After you run that command it won’t give you any output telling you that it successfully loaded so you can run this command write-host -foregroundcolor DarkGreen &#8220;Modules Loaded: $(get-module)&#8221; to have it tell you what Modules it currently has loaded. Alright that pretty much wraps it up for today. I know we didn’t do a lot with PowerShell and SQL Server yet but this gets some important ground work out of the way so that hopefully everyone is able to script along for the rest of the week. (If you&#8217;re dying to read ahead have a look at this post: Basic Querying From PowerShell) If you run into any issues please leave a comment and I’ll be glad to lend any help that I can. See all you back here tomorrow for the next post in this series Post 1. UPDATE: There seems to be an issue with loading the SQLServer Module as I had described. I have found this to be a work-around: Go to \\~\My Documents\WindowsPowerShell\Modules\SQLIse\Modules\ and copy everything except for the SQLISE folder, then go to the \\~\My Documents\WindowsPowerShell\Modules\ folder and paste all of those items. At this point you should now be able to run the command and get it to load up properly. I will post more when I found out other alternatives. del.icio.us Tags: SQL Server 2008,PowerShell,SQL University,Modules,Execution Policy,SQLPSX]]></description>
			<content:encoded><![CDATA[<p>Welcome to PowerShell Week at <a href="http://sqlchicken.com/sql-university/">SQL University</a>.  For regulars at SQLvariant, SQL University is something Jorge Segarra organized to get industry experts together to create learning courses around SQL Server.  These learning courses are in one week segments that focus on a specific area.</p>
<p>When I began blogging about PowerShell there were some complications based on your operating system. There were so many people blogging about these issues that I didn’t address it initially.  Since this is an introductory course I decided to go ahead and spin up a brand new Windows 7 VM so that I can walk you through these small but vital details.  If you don’t have Windows 7 this would be a great time to upgrade.  If you can&#8217;t upgrade then download PowerShell for you operating system from this <a href="http://support.microsoft.com/kb/968929">link</a>.  Now, onto getting started:</p>
<p><strong><em><span style="color: #004040;">Disclaimer:</span></em></strong><br />
PowerShell opens in a protected state as a security measure.  To enjoy the full power of PowerShell (and run scripts you downloaded off of the internet) you need to run without these safeguards. In today&#8217;s lesson we are simply launching PowerShell and priming it for the scripts and work we will interact with in the next several lessons.</p>
<p>To get started with PowerShell just click the Start button and type in ISE to locate the Integrated Script Editor in your program listing.  Right click and launch PowerShell in <em>Run as Adminsitrator</em> mode:</p>
<p><a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image1.png"><img title="image" style="display: inline; border-width: 0px;" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image_thumb.png" border="0" alt="image" width="288" height="178" /></a></p>
<p>Enter <span style="color: #0000ff;">Get-ExecutionPolicy </span>as a command. If you haven’t used PowerShell yet you will most likely see that the Execution Policy is set to “Restricted”.  You’ll need to run the command <span style="color: #0000ff;">Set-ExecutionPolicy</span> <span style="color: #8a2be2;">RemoteSigned</span> to be able to run the scripts and follow along with the lesson.  You’ll also get a popup that you’ll have to say yes to.</p>
<p><a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image2.png"><img title="image" style="display: inline; border-width: 0px;" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image_thumb1.png" border="0" alt="image" width="427" height="228" /></a></p>
<p>Your output should look very non-informative like this:</p>
<p><a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image5.png"><img title="image" style="display: inline; border-width: 0px;" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image_thumb4.png" border="0" alt="image" width="417" height="52" /></a></p>
<p>Now that we have that set let’s go to <a href="http://sqlpsx.codeplex.com/">SQLPSX.CodePlex.com</a> and and download the SQLPSX project.  It’s currently in version 2.2.1 and consists of 9 modules containing 133 advanced functions, only 2 cmdlets and 7 scripts.  It’s for working with ADO.NET, SMO, SQL Agent, RMO, SSIS, SQL script files and using the PowerShell ISE as a SQL query tool:</p>
<h3><span style="color: #ff0000;">NOTE:  Update at bottom with workaround:</span></h3>
<p><a href="http://sqlpsx.codeplex.com/"><img title="image" style="display: inline; border-width: 0px;" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image6.png" border="0" alt="image" width="390" height="222" /></a></p>
<p>During the installation we will run it without modifying the profile (just yet).</p>
<p><a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image7.png"><img title="image" style="display: inline; border-width: 0px;" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image_thumb5.png" border="0" alt="image" width="244" height="118" /></a></p>
<p>Once you’ve installed it successfully you should now have a WindowsPowerShell directory under your My Documents if you didn’t have one already (which is really important):</p>
<p><a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image8.png"><img title="image" style="display: inline; border-width: 0px;" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image_thumb6.png" border="0" alt="image" width="463" height="244" /></a></p>
<p>After it’s installed we should be able to open up the ISE again and run this command :</p>
<pre class="PowerShellColorizedScript"><span style="color: #0000ff;">Get-Module</span> <span style="color: #000080;">-ListAvailable</span></pre>
<p><a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image9.png"><img title="image" style="display: inline; border-width: 0px;" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image_thumb7.png" border="0" alt="image" width="465" height="361" /></a></p>
<p>And finally we’re going to get to the step where we load something up.  Run <span style="color: #0000ff;">import-module</span> <span style="color: #8a2be2;">SQLServer</span> to load up the main SQL Server module.  After you run that command it won’t give you any output telling you that it successfully loaded so you can run this command <span style="color: #0000ff;">write-host</span> <span style="color: #000080;">-foregroundcolor</span> <span style="color: #8a2be2;">DarkGreen</span> <span style="color: #8b0000;">&#8220;Modules Loaded: $(get-module)&#8221;</span> to have it tell you what Modules it currently has loaded.</p>
<p><a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image10.png"><img title="image" style="display: inline; border-width: 0px;" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/image_thumb8.png" border="0" alt="image" width="465" height="221" /></a></p>
<p>Alright that pretty much wraps it up for today.  I know we didn’t do a lot with PowerShell and SQL Server yet but this gets some important ground work out of the way so that hopefully everyone is able to script along for the rest of the week.  (If you&#8217;re dying to read ahead have a look at this post: <a href="http://bit.ly/9NWBuH">Basic Querying From PowerShell</a>)</p>
<p>If you run into any issues please leave a comment and I’ll be glad to lend any help that I can.  <strong>See all you back </strong><a href="http://sqlvariant.com/wordpress/index.php/2010/05/powershell-week-at-sql-university-post-1/"><strong>here tomorrow for the next post in this series Post 1</strong></a><strong>.</strong></p>
<h2><span style="color: #0000ff;"><span style="color: #ff0000;">UPDATE:</span></span></h2>
<p>There seems to be an issue with loading the SQLServer Module as I had described.  I have found this to be a work-around:  Go to <span style="color: #0000ff;">\\~\My Documents\WindowsPowerShell\Modules\SQLIse\Modules\</span> and copy everything except for the SQLISE folder, then go to the <span style="color: #0000ff;">\\~\My Documents\WindowsPowerShell\Modules\</span> folder and paste all of those items.  At this point you should now be able to run the command and get it to load up properly.</p>
<p>I will post more when I found out other alternatives.</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:27d1f5ad-4528-4c97-a29e-f1cff4612e79">del.icio.us Tags: <a href="http://del.icio.us/popular/SQL+Server+2008" rel="tag">SQL Server 2008</a>,<a href="http://del.icio.us/popular/PowerShell" rel="tag">PowerShell</a>,<a href="http://del.icio.us/popular/SQL+University" rel="tag">SQL University</a>,<a href="http://del.icio.us/popular/Modules" rel="tag">Modules</a>,<a href="http://del.icio.us/popular/Execution+Policy" rel="tag">Execution Policy</a>,<a href="http://del.icio.us/popular/SQLPSX" rel="tag">SQLPSX</a></div>
]]></content:encoded>
			<wfw:commentRss>http://sqlvariant.com/wordpress/index.php/2010/05/powershell-week-at-sql-university-post-0/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>The Scripts</title>
		<link>http://sqlvariant.com/wordpress/index.php/2010/05/the-scripts/</link>
		<comments>http://sqlvariant.com/wordpress/index.php/2010/05/the-scripts/#comments</comments>
		<pubDate>Tue, 11 May 2010 14:37:38 +0000</pubDate>
		<dc:creator>Aaron Nelson</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SQL Saturday]]></category>
		<category><![CDATA[Training Event]]></category>
		<category><![CDATA[Channel 9]]></category>
		<category><![CDATA[geekSpeak]]></category>
		<category><![CDATA[MSDN]]></category>

		<guid isPermaLink="false">http://sqlvariant.com/wordpress/?p=971</guid>
		<description><![CDATA[Last week I did a podcast for geekSpeak and a similar session at SQL Saturday #38 in Jacksonville.  I’ve already blogged about most of the scripts in those sessions but here is a download of a bunch of those scripts.  I have changed them a little from the way they were written in my session so that they can run independently without worrying about whether or not you need to load a snapin or module.  If you need it to run the script, it’s in there.  Don&#8217;t forget that for all but one of them you will either need to have SSMS 2008 installed or the SQLPSX codeplex project. If you don’t remember which script it was that you were interested in, here’s the recording of the session that I did for geekSpeak. Enjoy! Oh, and don’t forget Buck Woody’s disclaimer about running scripts you find on the internet: Script Disclaimer, for people who need to be told this sort of thing:    Never trust any script, including those that you find here, until you understand exactly what it does and how it will act on your systems. Always check the script on a test system or Virtual Machine, not a production system. All scripts on this site are performed by a professional stunt driver on a closed course. Your mileage may vary. Void where prohibited. Offer good for a limited time only. Keep out of reach of small children. Do not operate heavy machinery while using this script. If you experience blurry vision, indigestion or diarrhea during the operation of this script, see a physician immediately.   del.icio.us Tags: PowerShell,geekSpeak,MSDN,Channel 9,SQL Saturday]]></description>
			<content:encoded><![CDATA[<p>Last week I did a podcast for geekSpeak and a similar session at SQL Saturday #38 in Jacksonville.  I’ve already blogged about most of the scripts in those sessions but here is a download of a bunch of those <a href="http://bit.ly/ddweSA">scripts</a>.  I have changed them a little from the way they were written in my session so that they can run independently without worrying about whether or not you need to load a snapin or module.  If you need it to run the script, it’s in there.  Don&#8217;t forget that for all but one of them you will either need to have SSMS 2008 installed or the <a href="http://bit.ly/99DkEL">SQLPSX</a> codeplex project.</p>
<p>If you don’t remember which script it was that you were interested in, here’s the recording of the session that I did for <a href="http://bit.ly/cko3us">geekSpeak</a>.</p>
<p>Enjoy!</p>
<p><a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/PoSh1.png"><img style="display: inline; border-width: 0px;" title="PoSh" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/PoSh_thumb1.png" border="0" alt="PoSh" width="132" height="105" /></a></p>
<p>Oh, and don’t forget Buck Woody’s disclaimer about running scripts you find on the internet:</p>
<form id="aspnetForm" action="http://blogs.msdn.com/buckwoody/archive/2010/02/10/start-a-sql-server-agent-job-using-the-sql-server-powershell-provider.aspx" accept-charset="UNKNOWN" enctype="application/x-www-form-urlencoded" method="post">
<div id="container" style="width: 450px;">
<div id="wrapper">
<div id="content">
<div class="entryview">
<div><em style="mso-bidi-font-style: normal;"><span style="font-size: small;"><span style="font-family: Calibri;"><span style="color: #800000;"><strong>Script Disclaimer, for people who need to be told this sort of thing: </strong></span></span></span></em></div>
<div><em style="mso-bidi-font-style: normal;"><span style="font-size: small;"><span style="font-family: Calibri;"> </span></span></em></div>
<div><em style="mso-bidi-font-style: normal;"><span style="font-size: small;"><span style="font-family: Calibri;"> </span></span></em><em style="mso-bidi-font-style: normal;"><span style="font-size: small;"><span style="font-family: Calibri;"><span style="color: #800000;">Never trust any script, including those that you find here, until you understand exactly what it does and how it will act on your systems. Always check the script on a test system or Virtual Machine, not a production system. All scripts on this site are performed by a professional stunt driver on a closed course. Your mileage may vary. Void where prohibited. Offer good for a limited time only. Keep out of reach of small children. Do not operate heavy machinery while using this script. If you experience blurry vision, indigestion or diarrhea during the operation of this script, see a physician immediately. </span></span></span></em></div>
</div>
</div>
</div>
</div>
<p> </p>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:222d8669-7b6d-4fae-afa5-a34d7b198dd0" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">del.icio.us Tags: <a rel="tag" href="http://del.icio.us/popular/PowerShell">PowerShell</a>,<a rel="tag" href="http://del.icio.us/popular/geekSpeak">geekSpeak</a>,<a rel="tag" href="http://del.icio.us/popular/MSDN">MSDN</a>,<a rel="tag" href="http://del.icio.us/popular/Channel+9">Channel 9</a>,<a rel="tag" href="http://del.icio.us/popular/SQL+Saturday">SQL Saturday</a></div>
</form>
]]></content:encoded>
			<wfw:commentRss>http://sqlvariant.com/wordpress/index.php/2010/05/the-scripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>quick post checking mount points with PowerShell</title>
		<link>http://sqlvariant.com/wordpress/index.php/2010/05/quick-post-checking-mount-points-with-powershell/</link>
		<comments>http://sqlvariant.com/wordpress/index.php/2010/05/quick-post-checking-mount-points-with-powershell/#comments</comments>
		<pubDate>Thu, 06 May 2010 19:38:08 +0000</pubDate>
		<dc:creator>Aaron Nelson</dc:creator>
				<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://sqlvariant.com/wordpress/index.php/2010/05/quick-post-checking-mount-points-with-powershell/</guid>
		<description><![CDATA[Having problems with my blog feed so this is just a temporary post.  I hope to get things fixed this weekend.  Does anyone know how to fix a blog feed that is bigger than 512k? This code here will loop through a list of servers that you supply it in a text file and then spit out only the Mount Points on those servers that have less than 20% free space remaining on them. foreach ($svr in get-content "C:\PowerShell\AllServers.txt") { $svr; Get-WmiObject Win32_PerfFormattedData_PerfDisk_LogicalDisk -ComputerName $svr ` &#124; where{$_.Name -ne "_Total" -and $_.PercentFreeSpace -lt 20} &#124; select-object Name, PercentFreeSpace &#124; format-list }]]></description>
			<content:encoded><![CDATA[<p>Having problems with my blog feed so this is just a temporary post.  I hope to get things fixed this weekend.  Does anyone know how to fix a blog feed that is bigger than 512k?</p>
<p>This code here will loop through a list of servers that you supply it in a text file and then spit out only the Mount Points on those servers that have less than 20% free space remaining on them.</p>
<pre class="PowerShellColorizedScript"><span style="color: #00008b;">foreach</span> <span style="color: #000000;">(</span><span style="color: #ff4500;">$svr</span> <span style="color: #00008b;">in</span> <span style="color: #0000ff;">get-content</span> <span style="color: #8b0000;">"C:\PowerShell\AllServers.txt"</span><span style="color: #000000;">)</span>             

<span style="color: #000000;">{</span>             

<span style="color: #ff4500;">$svr</span><span style="color: #000000;">;</span> <span style="color: #0000ff;">Get-WmiObject</span> <span style="color: #8a2be2;">Win32_PerfFormattedData_PerfDisk_LogicalDisk</span> <span style="color: #000080;">-ComputerName</span> <span style="color: #ff4500;">$svr</span> <span style="color: #000000;">`
</span><span style="color: #a9a9a9;">|</span> <span style="color: #0000ff;">where</span><span style="color: #000000;">{</span><span style="color: #ff4500;">$_</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">Name</span> <span style="color: #a9a9a9;">-ne</span> <span style="color: #8b0000;">"_Total"</span> <span style="color: #a9a9a9;">-and</span> <span style="color: #ff4500;">$_</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">PercentFreeSpace</span> <span style="color: #a9a9a9;">-lt</span> <span style="color: #800080;">20</span><span style="color: #000000;">}</span> <span style="color: #a9a9a9;">|</span> <span style="color: #0000ff;">select-object</span> <span style="color: #8a2be2;">Name</span><span style="color: #a9a9a9;">,</span> <span style="color: #8a2be2;">PercentFreeSpace</span> <span style="color: #a9a9a9;">|</span> <span style="color: #0000ff;">format-list</span>            

<span style="color: #000000;">}</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://sqlvariant.com/wordpress/index.php/2010/05/quick-post-checking-mount-points-with-powershell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Picking up a New Hammer</title>
		<link>http://sqlvariant.com/wordpress/index.php/2010/05/picking-up-a-new-hammer/</link>
		<comments>http://sqlvariant.com/wordpress/index.php/2010/05/picking-up-a-new-hammer/#comments</comments>
		<pubDate>Tue, 04 May 2010 14:20:00 +0000</pubDate>
		<dc:creator>Aaron Nelson</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SMO]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://sqlvariant.com/wordpress/?p=925</guid>
		<description><![CDATA[The other day I was answering a question in the forums on PowerGUI.org that I thought would be a quick answer. The only problem was that I had my T-SQL hammer in my hand and not my PowerShell hammer. When I read the question I thought of a way to solve the problem using T-SQL and PowerShell; the only problem was I didn’t think outside of this toolset. PowerShell MVP Shay Levy ( blog &#124; twitter ) chimed in with a much better answer. Now granted I usually prefer to give answers that your typical data professionals will be comfortable with, ones that pass along a query, but in this case I have to go with the solution that you might not be as comfortable with. There’s a good reason though: It’s faster. here was my answer: #Only load this part once when you open up your PowerShell Session add-pssnapin SqlServerCmdletSnapin100 add-pssnapin SqlServerProviderSnapin100 #Create a text file in your c:\temp\ directory called AllServers.txt #Put each server\instance on a new line. foreach ($svr in get-content "C:\temp\AllServers.txt") { #sp_databases &#124; format-table invoke-sqlcmd -query "SELECT @@SERVERNAME AS 'ServerName', @@VERSION AS 'SQL Version'" -database master -serverinstance $svr &#62;&#62; "c:\temp\MySQLServerVersions.txt" } and here was Shay’s answer: $null = [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') Get-Content Allservers.txt &#124; Foreach-Object { $sql= New-Object Microsoft.SqlServer.Management.Smo.Server $_ $sql &#124; Select-Object @{n='ServerName';e={$sql.name}},@{n='Version';e={$sql.version}} } Without a doubt Shay’s answer is better because it returned the same results in a better format AND ran in a quarter of the time of my answer. In my environment my solution took a respectable 60 milliseconds to run, Shay’s answer using the SMO took 15 milliseconds. What’s my point today? The SMO is worth learning because it can be faster.� Where can you learn the SMO? I’m glad you asked Take a look at this MSDN article by SMO expert Allen White ( blog &#124; twitter ) del.icio.us Tags: SQL Server,PowerShell,SMO]]></description>
			<content:encoded><![CDATA[<p>The other day I was answering a question in the forums on <a href="http://powergui.org/index.jspa">PowerGUI.org</a> that I thought would be a quick answer.  The only problem was that I had my T-SQL hammer in my hand and not my PowerShell hammer.  When I read the question I thought of a way to solve the problem using T-SQL and PowerShell; the only problem was I didn’t think outside of this toolset.  PowerShell MVP Shay Levy ( <a href="http://blogs.microsoft.co.il/blogs/ScriptFanatic/">blog</a> | <a href="http://twitter.com/ShayLevy">twitter</a> ) chimed in with a much better answer.</p>
<p><a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/PoSh.png"><img title="PoSh" style="display: inline; border: 0px;" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/05/PoSh_thumb.png" border="0" alt="PoSh" width="132" height="105" /></a></p>
<p>Now granted I usually prefer to give answers that your typical data professionals will be comfortable with, ones that pass along a query, but in this case I have to go with the solution that you might not be as comfortable with.  There’s a good reason though:  <strong>It’s faster</strong>.</p>
<h5><span style="color: #0000a0;"><span style="text-decoration: underline;">here was my answer:</span></span></h5>
<pre class="PowerShellColorizedScript"><span style="color: #006400;">#Only load this part once when you open up your PowerShell Session</span>
<span style="color: #0000ff;">add-pssnapin</span> <span style="color: #8a2be2;">SqlServerCmdletSnapin100</span>
<span style="color: #0000ff;">add-pssnapin</span> <span style="color: #8a2be2;">SqlServerProviderSnapin100</span>            

<span style="color: #006400;">#Create a text file in your c:\temp\ directory called AllServers.txt</span>
<span style="color: #006400;">#Put each server\instance on a new line.</span>
<span style="color: #00008b;">foreach</span> <span style="color: #000000;">(</span><span style="color: #ff4500;">$svr</span> <span style="color: #00008b;">in</span> <span style="color: #0000ff;">get-content</span> <span style="color: #8b0000;">"C:\temp\AllServers.txt"</span><span style="color: #000000;">)</span>             

<span style="color: #000000;">{</span>
<span style="color: #006400;">#sp_databases | format-table</span>
<span style="color: #0000ff;">invoke-sqlcmd</span> <span style="color: #000080;">-query</span> <span style="color: #8b0000;">"SELECT @@SERVERNAME AS 'ServerName', @@VERSION AS 'SQL Version'"</span> <span style="color: #000080;">-database</span> <span style="color: #8a2be2;">master</span> <span style="color: #000080;">-serverinstance</span> <span style="color: #ff4500;">$svr</span> <span style="color: #a9a9a9;">&gt;&gt;</span> <span style="color: #8b0000;">"c:\temp\MySQLServerVersions.txt"</span>
<span style="color: #000000;">}</span></pre>
<h5><span style="color: #0000a0;"><span style="text-decoration: underline;">and here was Shay’s answer:</span></span></h5>
<pre class="PowerShellColorizedScript"><span style="color: #ff4500;">$null</span> <span style="color: #a9a9a9;">=</span> <span style="color: #008080;">[System.Reflection.Assembly]</span><span style="color: #a9a9a9;">::</span><span style="color: #000000;">LoadWithPartialName</span><span style="color: #000000;">(</span><span style="color: #8b0000;">'Microsoft.SqlServer.SMO'</span><span style="color: #000000;">)</span>            

<span style="color: #0000ff;">Get-Content</span> <span style="color: #8a2be2;">Allservers.txt</span> <span style="color: #a9a9a9;">|</span> <span style="color: #0000ff;">Foreach-Object</span> <span style="color: #000000;">{</span>
   <span style="color: #ff4500;">$sql</span><span style="color: #a9a9a9;">=</span> <span style="color: #0000ff;">New-Object</span> <span style="color: #8a2be2;">Microsoft.SqlServer.Management.Smo.Server</span> <span style="color: #ff4500;">$_</span>
   <span style="color: #ff4500;">$sql</span> <span style="color: #a9a9a9;">|</span> <span style="color: #0000ff;">Select-Object</span> <span style="color: #000000;">@{</span><span style="color: #000000;">n</span><span style="color: #a9a9a9;">=</span><span style="color: #8b0000;">'ServerName'</span><span style="color: #000000;">;</span><span style="color: #000000;">e</span><span style="color: #a9a9a9;">=</span><span style="color: #000000;">{</span><span style="color: #ff4500;">$sql</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">name</span><span style="color: #000000;">}</span><span style="color: #000000;">}</span><span style="color: #a9a9a9;">,</span><span style="color: #000000;">@{</span><span style="color: #000000;">n</span><span style="color: #a9a9a9;">=</span><span style="color: #8b0000;">'Version'</span><span style="color: #000000;">;</span><span style="color: #000000;">e</span><span style="color: #a9a9a9;">=</span><span style="color: #000000;">{</span><span style="color: #ff4500;">$sql</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">version</span><span style="color: #000000;">}</span><span style="color: #000000;">}</span>
<span style="color: #000000;">}</span></pre>
<p>Without a doubt Shay’s answer is better because it returned the same results in a better format <strong>AND</strong> ran in a quarter of the time of my answer.  In my environment my solution took a respectable 60 milliseconds to run, Shay’s answer using the SMO took 15 milliseconds.  What’s my point today?  The SMO is worth learning because it can be faster.�<br />
<em>Where can you learn the SMO?</em> I’m glad you asked <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />   Take a look at this <a href="http://msdn.microsoft.com/en-us/library/dd938892.aspx">MSDN article</a> by SMO expert Allen White ( <a href="http://sqlblog.com/blogs/allen_white/default.aspx">blog</a> | <a href="http://twitter.com/SQLRunr">twitter</a> )</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:cf1960c4-c579-4a87-86d2-186de8d9e113">del.icio.us Tags: <a href="http://del.icio.us/popular/SQL+Server" rel="tag">SQL Server</a>,<a href="http://del.icio.us/popular/PowerShell" rel="tag">PowerShell</a>,<a href="http://del.icio.us/popular/SMO" rel="tag">SMO</a></div>
]]></content:encoded>
			<wfw:commentRss>http://sqlvariant.com/wordpress/index.php/2010/05/picking-up-a-new-hammer/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Get-Sales &#124; Out-Map = T-SQL Tuesday #005 &#8211; Reporting</title>
		<link>http://sqlvariant.com/wordpress/index.php/2010/04/get-sales-out-map-t-sql-tuesday-005-reporting/</link>
		<comments>http://sqlvariant.com/wordpress/index.php/2010/04/get-sales-out-map-t-sql-tuesday-005-reporting/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 22:51:00 +0000</pubDate>
		<dc:creator>Aaron Nelson</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[T-SQL Tuesday]]></category>

		<guid isPermaLink="false">http://sqlvariant.com/wordpress/?p=820</guid>
		<description><![CDATA[For this month’s T-SQL Tuesday I thought I’d go with something useful that I’ve been meaning to blog about for weeks now.  While listening to the PowerScripting Podcast a few month’s back I heard about a product that sounded really cool for simple data visualization and quickly showing people just how powerful PowerShell is.  Now to get this to work using all the code on the screen you’ll at least have to download the trial version of of the Power Gadgets however even without the method I describe is important if you’re new to this type of reporting (desktop gadgets). Turns out this little piece of software had even more packed into it than I was hoping for.  I needed a piece of software that could allow me to pipe data to it to display it in a desktop gadget as a list. Before I show you how to setup this quick-and-easy tool to create desktop gadgets I want to issue a warning against setting up this type of thing directly against your production database; read all the way through or don’t blame me when you bring your production environment down. What you want to do (at the very least) is to have all of the gadgets that you deploy read from a central location where they only have to scoop up the results of the query that you’re trying to report on, and not 400 gadgets running the query itself.  An easy way to accomplish this would be to run the query in an Agent Job against your production environment (assuming that you don’t have a live reporting copy) and deposit those results in a table.  Let’s see if we can step through an example with the AdventureWorks database. If this below were your query to show your sales for today… SELECT SUM(SOD.OrderQty) AS &#8216;OrderQty&#8216;, s.StateProvinceCode   FROM Sales.SalesOrderHeader SOH  INNER JOIN Sales.SalesOrderDetail SOD     ON SOH.SalesOrderID = SOD.SalesOrderID   JOIN Production.Product P     ON SOD.ProductID = P.ProductID   JOIN Person.Address A     ON SOH.BillToAddressID = A.AddressID   JOIN Person.StateProvince S     ON A.StateProvinceID = S.StateProvinceID  WHERE SOH.OrderDate = &#8217;2001-07-01 00:00:00.000&#8242; &#8211;&#60;&#8212;This would get GETDATE() or something  GROUP BY S.StateProvinceCode …you would really want to create an Agent Job to load that into a table and select off of the table.  For simplicity we’ll leave out the job and just use the queries. /* &#60;Do this part only one time&#62;*/ USE [AdventureWorks] GO CREATE SCHEMA [Report] AUTHORIZATION [dbo] GO CREATE TABLE [Report].[TodaysSalesOrderByState]( [OrderQty] [int] NULL, [StateProvinceCode] [nchar](3) NOT NULL, [LastLoadTime] DATETIME NOT NULL CONSTRAINT [DF_LastLoadTime] DEFAULT GETDATE() ) ON [PRIMARY] /* &#60;/Do this part only one time&#62;*/ Then this… /* &#60;This is the part that would eventually go into an agent job, along with a delete statement before it that was in the same transaction&#62;*/  INSERT INTO Report.TodaysSalesOrderByState ( [OrderQty], [StateProvinceCode]) SELECT SUM(SOD.OrderQty) AS &#8216;OrderQty&#8216;, s.StateProvinceCode   FROM Sales.SalesOrderHeader SOH  INNER JOIN Sales.SalesOrderDetail SOD     ON SOH.SalesOrderID = SOD.SalesOrderID   JOIN Production.Product P     ON SOD.ProductID = P.ProductID   JOIN Person.Address A     ON SOH.BillToAddressID = A.AddressID   JOIN Person.StateProvince S     ON A.StateProvinceID = S.StateProvinceID  WHERE SOH.OrderDate = &#8217;2001-07-01 00:00:00.000&#8242; &#8211;&#60;&#8212;This would get GETDATE() or something  GROUP BY S.StateProvinceCode /* &#60;/This is the part that would eventually go into an agent job&#62;*/ Now you’ll want to create a stored proc that will be used to call the report data.  It will also make creating the report nice and clean. CREATE PROCEDURE [dbo].[rp_MapThat] AS  SELECT [OrderQty]       ,[StateProvinceCode] AS &#8216;State&#8217;   FROM [AdventureWorks].[Report].[TodaysSalesOrderByState] GO After that all you have to do is to go ahead and create the gadget using this little script: #Go ahead and add the SQL Snapins add-pssnapin SqlServerCmdletSnapin100 add-pssnapin SqlServerProviderSnapin100 #add the Gadgets Snapin add-pssnapin PowerGadgets invoke-sqlcmd -query "EXEC dbo.rp_MapThat" -database AdventureWorks -serverinstance WIN7\KILIMANJARO &#124; out-map -values OrderQty -label State -title "CountByState" -refresh 0:1:0   And now you’ve got a gadget prototype.  I’m sure you can figure out how to turn it into an operational gadget for your company.     LiveJournal Tags: T-SQL]]></description>
			<content:encoded><![CDATA[<p>For this month’s <a href="http://sqlvariant.com/wordpress/index.php/2010/04/t-sql-tuesday-005-reporting/">T-SQL Tuesday</a> I thought I’d go with something useful that I’ve been meaning to blog about for weeks now.  While listening to the <a href="http://powerscripting.wordpress.com/">PowerScripting Podcast</a> a few month’s back I heard about a product that sounded really cool for simple <a href="http://www.softwarefx.com/sfxSqlProducts/powergadgets/">data visualization</a> and quickly showing people just how powerful PowerShell is.  Now to get this to work using all the code on the screen you’ll at least have to download the trial version of of the Power Gadgets however even without the method I describe is important if you’re new to this type of reporting (desktop gadgets).</p>
<p>Turns out this little piece of software had even more packed into it than I was hoping for.  I needed a piece of software that could allow me to pipe data to it to display it in a desktop gadget as a list.</p>
<p>Before I show you how to setup this quick-and-easy tool to create desktop gadgets I want to issue a warning against setting up this type of thing <strong>directly</strong> against your production database; read all the way through or don’t blame me when you bring your production environment down.</p>
<p><a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/04/image2.png"><img style="display: inline; border-width: 0px;" title="image" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/04/image_thumb2.png" border="0" alt="image" width="616" height="407" /></a></p>
<p>What you want to do (at the very least) is to have all of the gadgets that you deploy read from a central location where they only have to scoop up the <strong>results</strong> of the query that you’re trying to report on, and not 400 gadgets running the query itself.  An easy way to accomplish this would be to run the query in an Agent Job against your production environment (assuming that you don’t have a live reporting copy) and deposit those results in a table.  Let’s see if we can step through an example with the AdventureWorks database.</p>
<h4>If this below were your query to show your sales for today…</h4>
<p><span style="font-family: calibri; color: blue; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">SELECT</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: fuchsia; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: fuchsia; mso-style-textfill-fill-alpha: 100.0%;">SUM</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">(</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">SOD</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">OrderQty</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">)</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: blue; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">AS</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: red; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: red; mso-style-textfill-fill-alpha: 100.0%;">&#8216;</span><span style="font-family: calibri; color: red; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: red; mso-style-textfill-fill-alpha: 100.0%;">OrderQty</span><span style="font-family: calibri; color: red; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: red; mso-style-textfill-fill-alpha: 100.0%;">&#8216;</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">,</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">s</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">StateProvinceCode<br />
</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"><span style="mso-spacerun: yes;">  </span></span><span style="font-family: calibri; color: blue; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">FROM</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">Sales</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">SalesOrderHeader</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> SOH<br />
</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"><span style="mso-spacerun: yes;"> </span></span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">INNER</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">JOIN</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">Sales</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">SalesOrderDetail</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> SOD<br />
</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"><span style="mso-spacerun: yes;">    </span></span><span style="font-family: calibri; color: blue; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">ON</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">SOH</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">SalesOrderID</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">=</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">SOD</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">SalesOrderID<br />
</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"><span style="mso-spacerun: yes;">  </span></span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">JOIN</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">Production</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">Product</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> P<br />
</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"><span style="mso-spacerun: yes;">    </span></span><span style="font-family: calibri; color: blue; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">ON</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">SOD</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">ProductID</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">=</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">P</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">ProductID<br />
</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"><span style="mso-spacerun: yes;">  </span></span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">JOIN</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">Person</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: blue; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">Address</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> A<br />
</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"><span style="mso-spacerun: yes;">    </span></span><span style="font-family: calibri; color: blue; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">ON</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">SOH</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">BillToAddressID</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">=</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">A</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">AddressID<br />
</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"><span style="mso-spacerun: yes;">  </span></span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">JOIN</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">Person</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">StateProvince</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> S<br />
</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"><span style="mso-spacerun: yes;">    </span></span><span style="font-family: calibri; color: blue; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">ON</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">A</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">StateProvinceID</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">=</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">S</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">StateProvinceID<br />
</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"><span style="mso-spacerun: yes;"> </span></span><span style="font-family: calibri; color: blue; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">WHERE</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">SOH</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">OrderDate</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">=</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: red; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: red; mso-style-textfill-fill-alpha: 100.0%;">&#8217;2001-07-01 00:00:00.000&#8242;</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: green; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: green; mso-style-textfill-fill-alpha: 100.0%;">&#8211;&lt;&#8212;This would get GETDATE() or something<br />
</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"><span style="mso-spacerun: yes;"> </span></span><span style="font-family: calibri; color: blue; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">GROUP</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: blue; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">BY</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">S</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">StateProvinceCode</span></p>
<h4>…you would really want to create an Agent Job to load that into a table and select off of the table.  For simplicity we’ll leave out the job and just use the queries.</h4>
<p style="text-align: left; line-height: 115%; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"><span style="font-family: &amp;amp;amp; color: green; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: green; mso-style-textfill-fill-alpha: 100.0%;">/* &lt;Do this part only one time&gt;*/</span></p>
<p style="text-align: left; line-height: 115%; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"><span style="font-family: &amp;amp;amp; color: blue; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">USE</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;"> [</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;">AdventureWorks</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;">]</span></p>
<p style="text-align: left; line-height: 115%; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"><span style="font-family: &amp;amp;amp; color: blue; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">GO</span></p>
<p style="text-align: left; line-height: 115%; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"><span style="font-family: &amp;amp;amp; color: blue; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">CREATE</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;"> </span><span style="font-family: &amp;amp;amp; color: blue; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">SCHEMA</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;"> [Report] </span><span style="font-family: &amp;amp;amp; color: blue; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">AUTHORIZATION</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;"> [</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;">dbo</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;">]</span></p>
<p style="text-align: left; line-height: 115%; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"><span style="font-family: &amp;amp;amp; color: blue; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">GO</span></p>
<p style="text-align: left; line-height: 115%; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"><span style="font-family: &amp;amp;amp; color: blue; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">CREATE</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;"> </span><span style="font-family: &amp;amp;amp; color: blue; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">TABLE</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;"> [Report]</span><span style="font-family: &amp;amp;amp; color: gray; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;">[</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;">TodaysSalesOrderByState</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;">]</span><span style="font-family: &amp;amp;amp; color: gray; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">(</span></p>
<p style="text-align: left; line-height: 115%; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;">[</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;">OrderQty</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;">] [</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;">int</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;">] </span><span style="font-family: &amp;amp;amp; color: gray; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">NULL,</span></p>
<p style="text-align: left; line-height: 115%; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;">[</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;">StateProvinceCode</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;">] [</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;">nchar</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;">]</span><span style="font-family: &amp;amp;amp; color: gray; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">(</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;">3</span><span style="font-family: &amp;amp;amp; color: gray; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">)</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;"> </span><span style="font-family: &amp;amp;amp; color: gray; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">NOT</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;"> </span><span style="font-family: &amp;amp;amp; color: gray; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">NULL,</span></p>
<p style="text-align: left; line-height: 115%; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;">[</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;">LastLoadTime</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;">] </span><span style="font-family: &amp;amp;amp; color: blue; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">DATETIME</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;"> </span><span style="font-family: &amp;amp;amp; color: gray; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">NOT</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;"> </span><span style="font-family: &amp;amp;amp; color: gray; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">NULL</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;"> </span><span style="font-family: &amp;amp;amp; color: blue; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">CONSTRAINT</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;"> [</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;">DF_LastLoadTime</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;">] </span><span style="font-family: &amp;amp;amp; color: blue; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">DEFAULT</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;"> </span><span style="font-family: &amp;amp;amp; color: fuchsia; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: fuchsia; mso-style-textfill-fill-alpha: 100.0%;">GETDATE</span><span style="font-family: &amp;amp;amp; color: gray; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">()</span></p>
<p style="text-align: left; line-height: 115%; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"><span style="font-family: &amp;amp;amp; color: gray; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">)</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;"> </span><span style="font-family: &amp;amp;amp; color: blue; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">ON</span><span style="font-family: &amp;amp;amp; color: black; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-alpha: 100.0%; mso-color-index: 1; mso-style-textfill-fill-themecolor: text1;"> [PRIMARY]</span></p>
<p style="text-align: left; line-height: 115%; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 10pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"><span style="font-family: &amp;amp;amp; color: green; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp;amp; mso-fareast-font-family: calibri; mso-bidi-font-family: &amp;amp;amp; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: green; mso-style-textfill-fill-alpha: 100.0%;">/* &lt;/Do this part only one time&gt;*/</span></p>
<h4>Then this…</h4>
<p style="text-align: left; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"><span style="font-family: &amp;amp; color; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp; mso-fareast-font-family; mso-bidi-font-family: &amp;amp; mso-font-kerning; mso-style-textfill-type: solid; mso-style-textfill-fill-color: green; mso-style-textfill-fill-alpha: 100.0%;"><span style="color: #008000;">/* &lt;This is the part that would eventually go into an agent job, along with a delete statement before it that was in the same transaction&gt;*/</span></span></p>
<p style="text-align: left; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"><span style="font-family: &amp;amp; color; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp; mso-fareast-font-family; mso-bidi-font-family: &amp;amp; mso-font-kerning; mso-style-textfill-type: solid; mso-style-textfill-fill-color: green; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: blue; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">INSERT</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: blue; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">INTO</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">Report</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">TodaysSalesOrderByState</span><span style="font-family: calibri; color: blue; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">(</span></p>
<p style="text-align: left; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">[</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">OrderQty</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">]</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">,</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span></p>
<p style="text-align: left; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">[</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">StateProvinceCode</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">]</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">)</span></p>
<p style="text-align: left; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"><span style="font-family: calibri; color: blue; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">SELECT</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: fuchsia; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: fuchsia; mso-style-textfill-fill-alpha: 100.0%;">SUM</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">(</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">SOD</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">OrderQty</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">)</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: blue; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">AS</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: red; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: red; mso-style-textfill-fill-alpha: 100.0%;">&#8216;</span><span style="font-family: calibri; color: red; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: red; mso-style-textfill-fill-alpha: 100.0%;">OrderQty</span><span style="font-family: calibri; color: red; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: red; mso-style-textfill-fill-alpha: 100.0%;">&#8216;</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">,</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">s</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">StateProvinceCode</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span></p>
<p style="text-align: left; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"><span style="mso-spacerun: yes;">  </span></span><span style="font-family: calibri; color: blue; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">FROM</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">Sales</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">SalesOrderHeader</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> SOH</span></p>
<p style="text-align: left; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"><span style="mso-spacerun: yes;"> </span></span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">INNER</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">JOIN</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">Sales</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">SalesOrderDetail</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> SOD</span></p>
<p style="text-align: left; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"><span style="mso-spacerun: yes;">    </span></span><span style="font-family: calibri; color: blue; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">ON</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">SOH</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">SalesOrderID</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">=</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">SOD</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">SalesOrderID</span></p>
<p style="text-align: left; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"><span style="mso-spacerun: yes;">  </span></span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">JOIN</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">Production</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">Product</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> P</span></p>
<p style="text-align: left; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"><span style="mso-spacerun: yes;">    </span></span><span style="font-family: calibri; color: blue; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">ON</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">SOD</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">ProductID</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">=</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">P</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">ProductID</span></p>
<p style="text-align: left; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"><span style="mso-spacerun: yes;">  </span></span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">JOIN</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">Person</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: blue; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">Address</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> A</span></p>
<p style="text-align: left; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"><span style="mso-spacerun: yes;">    </span></span><span style="font-family: calibri; color: blue; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">ON</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">SOH</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">BillToAddressID</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">=</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">A</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">AddressID</span></p>
<p style="text-align: left; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"><span style="mso-spacerun: yes;">  </span></span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">JOIN</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">Person</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">StateProvince</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> S</span></p>
<p style="text-align: left; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"><span style="mso-spacerun: yes;">    </span></span><span style="font-family: calibri; color: blue; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">ON</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">A</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">StateProvinceID</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">=</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">S</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">StateProvinceID</span></p>
<p style="text-align: left; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"><span style="mso-spacerun: yes;"> </span></span><span style="font-family: calibri; color: blue; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">WHERE</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">SOH</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">OrderDate</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">=</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: red; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: red; mso-style-textfill-fill-alpha: 100.0%;">&#8217;2001-07-01 00:00:00.000&#8242;</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: green; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: green; mso-style-textfill-fill-alpha: 100.0%;">&#8211;&lt;&#8212;This would get GETDATE() or something</span></p>
<p style="text-align: left; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"><span style="mso-spacerun: yes;"> </span></span><span style="font-family: calibri; color: blue; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">GROUP</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: blue; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: blue; mso-style-textfill-fill-alpha: 100.0%;">BY</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">S</span><span style="font-family: calibri; color: gray; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: gray; mso-style-textfill-fill-alpha: 100.0%;">.</span><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;">StateProvinceCode</span></p>
<p style="text-align: left; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"><span style="font-family: &amp;amp; color; font-size: 9pt; language: en-us; mso-ascii-font-family: &amp;amp; mso-fareast-font-family; mso-bidi-font-family: &amp;amp; mso-font-kerning; mso-style-textfill-type: solid; mso-style-textfill-fill-color: green; mso-style-textfill-fill-alpha: 100.0%;"><span style="color: #008000;">/* &lt;/This is the part that would eventually go into an agent job&gt;*/</span></span></p>
<h4>Now you’ll want to create a stored proc that will be used to call the report data.  It will also make creating the report nice and clean.</h4>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;quot;Courier New&amp;quot;; color: blue; font-size: 10pt; mso-no-proof: yes;">CREATE</span><span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-no-proof: yes;"> <span style="color: blue;">PROCEDURE</span> [dbo]<span style="color: gray;">.</span>[rp_MapThat]<br />
</span><span style="font-family: &amp;quot;Courier New&amp;quot;; color: blue; font-size: 10pt; mso-no-proof: yes;">AS</span><span style="font-family: &amp;quot;Courier New&amp;quot;; color: blue; font-size: 10pt; mso-no-proof: yes;"> </p>
<p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none;"><span style="font-family: &amp;quot;Courier New&amp;quot;; color: blue; font-size: 10pt; mso-no-proof: yes;">SELECT</span><span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-no-proof: yes;"> [OrderQty]<br />
</span><span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: gray;">,</span>[StateProvinceCode] <span style="color: blue;">AS</span> <span style="color: red;">&#8216;State&#8217;<br />
</span></span><span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">  </span><span style="color: blue;">FROM</span> [AdventureWorks]<span style="color: gray;">.</span>[Report]<span style="color: gray;">.</span>[TodaysSalesOrderByState]<br />
</span><span style="font-family: &amp;quot;Courier New&amp;quot;; color: blue; font-size: 10pt; mso-no-proof: yes;">GO</span></p>
<h4>After that all you have to do is to go ahead and create the gadget using this little script:</h4>
<pre class="PowerShellColorizedScript"><span style="color: #006400;">#Go ahead and add the SQL Snapins</span>
<span style="color: #0000ff;">add-pssnapin</span> <span style="color: #8a2be2;">SqlServerCmdletSnapin100</span>
<span style="color: #0000ff;">add-pssnapin</span> <span style="color: #8a2be2;">SqlServerProviderSnapin100</span>
<span style="color: #006400;">#add the Gadgets Snapin</span>
<span style="color: #0000ff;">add-pssnapin</span> <span style="color: #8a2be2;">PowerGadgets</span>            

<span style="color: #0000ff;">invoke-sqlcmd</span> <span style="color: #000080;">-query</span> <span style="color: #8b0000;">"EXEC dbo.rp_MapThat"</span> <span style="color: #000080;">-database</span> <span style="color: #8a2be2;">AdventureWorks</span> <span style="color: #000080;">-serverinstance</span> <span style="color: #8a2be2;">WIN7\KILIMANJARO</span> <span style="color: #a9a9a9;">|</span> <span style="color: #0000ff;">out-map</span> <span style="color: #000080;">-values</span> <span style="color: #8a2be2;">OrderQty</span> <span style="color: #000080;">-label</span> <span style="color: #8a2be2;">State</span> <span style="color: #000080;">-title</span> <span style="color: #8b0000;">"CountByState"</span> <span style="color: #000080;">-refresh</span> <span style="color: #8a2be2;">0:1:0</span></pre>
<p style="text-align: left; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"> </p>
<p style="text-align: left; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;">And now you’ve got a gadget prototype.  I’m sure you can figure out how to turn it into an operational gadget for your company.</p>
<p style="text-align: left; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span></p>
<p style="text-align: left; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;"><span style="font-family: calibri; color: black; font-size: 10pt; language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: +mn-ea; mso-bidi-font-family: +mn-cs; mso-font-kerning: 12.0pt; mso-style-textfill-type: solid; mso-style-textfill-fill-color: black; mso-style-textfill-fill-alpha: 100.0%;"> </span></p>
<p style="text-align: left; line-height: 115%; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;">
<p style="text-align: left; line-height: 115%; margin-top: 0pt; unicode-bidi: embed; direction: ltr; margin-bottom: 0pt; margin-left: 0in; word-break: normal; language: en-us; mso-line-break-override: none; punctuation-wrap: hanging;">
<div class="wlWriterSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">LiveJournal Tags: <a rel="tag" href="http://www.livejournal.com/interests.bml?int=T-SQL">T-SQL</a></div>
]]></content:encoded>
			<wfw:commentRss>http://sqlvariant.com/wordpress/index.php/2010/04/get-sales-out-map-t-sql-tuesday-005-reporting/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Checking Disk Space with PowerShell</title>
		<link>http://sqlvariant.com/wordpress/index.php/2010/02/checking-disk-space-with-powershell/</link>
		<comments>http://sqlvariant.com/wordpress/index.php/2010/02/checking-disk-space-with-powershell/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 03:06:27 +0000</pubDate>
		<dc:creator>Aaron Nelson</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Disk Space]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://sqlvariant.com/wordpress/?p=669</guid>
		<description><![CDATA[This is another one of the code examples that I did in my PowerShell for Data Professionals session last week.  If you give it your computer name and then run it you will get back a stream or properties like I mentioned during the session.  get-wmiobject -query ` "Select DeviceID,Size,Freespace from Win32_logicaldisk where drivetype=3" ` -computer "YourComputerName" Now this runs fine but it brings back quite a bit more information than we really need.  I mean we specified columns in our WQL statement and it brought back the kitchen sink almost as if we had given it a SELECT *.  Now I don’t know why this happens I just know that it does (I have emailed a few people but haven’t heard back yet).  To get around this problemfeature all you have to do is take the output from the command you executed and pipe it to the Select-Object cmdlet and specify the columns that you want again. get-wmiobject -query ` "Select DeviceID,Size,Freespace from Win32_logicaldisk where drivetype=3" ` -computer "YourComputerName" &#124; select-object DeviceID, Size, FreeSpace And voilà you have now taken something from the pipeline and done something with it that hopefully any SQL person in the world can understand.  So what’s next?  Well just change -computer again to the name of your favorite Dev server and see how much disk space you have. *Don&#8217;t forget the disclaimer about running other people&#8217;s scripts! Here&#8217;s the link to the msdn article that will have more info on those properties and the methods that you can use against http://msdn.microsoft.com/en-us/library/aa394173(VS.85).aspx]]></description>
			<content:encoded><![CDATA[<p>This is another one of the code examples that I did in my <a href="http://bit.ly/bl0EdI">PowerShell for Data Professionals</a> session last week.  If you give it your computer name and then run it you will get back a stream or properties like I mentioned during the session. </p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" class="csharpcode">
<pre class="PowerShellColorizedScript"><span style="color: #0000ff;">get-wmiobject</span> <span style="color: #000080;">-query</span> `
<span style="color: #8b0000;">"Select DeviceID,Size,Freespace from Win32_logicaldisk where drivetype=3"</span> `
<span style="color: #000080;">-computer</span> <span style="color: #8b0000;">"YourComputerName"
</span></pre>
<p>Now this runs fine but it brings back quite a bit more information than we really need.  I mean we specified columns in our WQL statement and it brought back the kitchen sink almost as if we had given it a SELECT *.  Now I don’t know why this happens I just know that it does (I have emailed a few people but haven’t heard back yet).  To get around this <span style="text-decoration: line-through;">problem</span>feature all you have to do is take the output from the command you executed and <span style="text-decoration: underline;">pipe it</span> to the <span style="color: #0000ff;">Select-Object</span> cmdlet and specify the columns that you want again.</p>
</div>
</div>
<div id="codeSnippetWrapper">
<div id="codeSnippet" class="csharpcode">
<pre class="PowerShellColorizedScript"><span style="color: #0000ff;">get-wmiobject</span> <span style="color: #000080;">-query</span> <span style="color: #000000;">`
</span><span style="color: #8b0000;">"Select DeviceID,Size,Freespace from Win32_logicaldisk where drivetype=3"</span> `
<span style="color: #000080;">-computer</span> <span style="color: #8b0000;">"YourComputerName"</span> <span style="color: #a9a9a9;">|</span> <span style="color: #0000ff;">select-object</span> <span style="color: #8a2be2;">DeviceID</span><span style="color: #a9a9a9;">,</span> <span style="color: #8a2be2;">Size</span><span style="color: #a9a9a9;">,</span> <span style="color: #8a2be2;">FreeSpace
</span></pre>
<p class="PowerShellColorizedScript">And voilà you have now taken something from the pipeline and done something with it that hopefully any SQL person in the world can understand.  So what’s next?  Well just change <span style="color: #000080;">-computer</span> again to the name of your favorite Dev server and see how much disk space you have.</p>
<p class="PowerShellColorizedScript"><strong><em><span style="color: #800000;">*Don&#8217;t forget the disclaimer about running other people&#8217;s scripts!</span></em></strong></p>
<p class="PowerShellColorizedScript">Here&#8217;s the link to the msdn article that will have more info on those properties and the methods that you can use against</p>
<p><!--CRLF--></p>
</div>
</div>
<p><a title="http://msdn.microsoft.com/en-us/library/aa394173(VS.85).aspx" href="http://msdn.microsoft.com/en-us/library/aa394173(VS.85).aspx">http://msdn.microsoft.com/en-us/library/aa394173(VS.85).aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sqlvariant.com/wordpress/index.php/2010/02/checking-disk-space-with-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get More Done with SQLPSX</title>
		<link>http://sqlvariant.com/wordpress/index.php/2010/02/get-more-done-with-sqlpsx/</link>
		<comments>http://sqlvariant.com/wordpress/index.php/2010/02/get-more-done-with-sqlpsx/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 09:00:00 +0000</pubDate>
		<dc:creator>Aaron Nelson</dc:creator>
				<category><![CDATA[AppDev]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Backups]]></category>
		<category><![CDATA[Modules]]></category>
		<category><![CDATA[RTFM]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQLPSX]]></category>

		<guid isPermaLink="false">http://sqlvariant.com/wordpress/?p=652</guid>
		<description><![CDATA[In my LiveMeeting session for the AppDev Virtual Chapter of PASS yesterday I talked about building on top of tools that others had already built for you to use.  A great one for any DBA to use is the SQL PowerShell Extensions known as SQLPSX.  Even if you’ve never used PowerShell before you should take a look at this.  Heck even Sys Admins in shops that don’t have a DBA should have a look at this.  I have found the commands I have worked with very easy to use; even easier than T-SQL in some cases. After you download the files and RTFM you can then you can follow along on this next part.  Oh wait, first a little warning straight from Buck Woody: Script Disclaimer, for people who need to be told this sort of thing:   Never trust any script, including those that you find here, until you understand exactly what it does and how it will act on your systems. Always check the script on a test system or Virtual Machine, not a production system. All scripts on this site are performed by a professional stunt driver on a closed course. Your mileage may vary. Void where prohibited. Offer good for a limited time only. Keep out of reach of small children. Do not operate heavy machinery while using this script. If you experience blurry vision, indigestion or diarrhea during the operation of this script, see a physician immediately. get-module -listAvailable import-module SQLServer Invoke-SqlBackup -sqlserver "WINX64ULT7\Kilimanjaro" -dbname "AdventureWorks" ` -filepath "C:\Temp\AdventureWorks_db_$(((Get-Date).ToString("yyyyMMddHHmm"))).bak" Now this little script here (above) will backup a db for you and even include the current YearMonthDayHourMinute in the file string.  This one below will backup all of the non-system databases on your instance.  If you’re like me you’re thinking this doesn’t do anything that you can’t already do today with a maintenance plan.  That’s true and maybe I should have titled this post &#8220;Get Something Done with SQLPSX&#8221; but I will build on how you can leverage this more tomorrow.  For now, why don’t you add an AND clause only backup all the databases that start with ‘A’ foreach ($dbn in invoke-sqlcmd -query "SELECT name FROM sys.databases WHERE owner_sid !=0x01" ` -database master -serverinstance WIN7\Kilimanjaro ) { $k="C:\Temp\" + $($dbn.name) + "_db_$(((Get-Date).ToString("yyyyMMddHHmm"))).bak"WIN7\Kilimanjaro" -dbname $($dbn.name) -filepath $k $dbn; Invoke-SQLBackup -sqlserver " } I’ve gone ahead and included the SQLPSX help items here.  Please see if there’s one that catches your eye and see if it might work for you. * Get-AgentAlert * Get-AgentAlertCategory * Get-AgentJob * Get-AgentJobHistory * Get-AgentJobSchedule * Get-AgentJobServer * Get-AgentJobStep * Get-AgentOperator * Get-AgentOperatorCategory * Get-AgentProxyAccount * Get-AgentSchedule * Get-AgentTargetServer * Get-AgentTargetServerGroup * Set-AgentJobHistoryFilter * Get-ReplArticle * Get-ReplEnumLogReaderAgent * Get-ReplEnumPublications * Get-ReplEnumPublications2 * Get-ReplEnumSnapshotAgent * Get-ReplEnumSubscriptions * Get-ReplEnumSubscriptions2 * Get-ReplLightPublication * Get-ReplMonitor * Get-ReplPublication * Get-ReplPublicationMonitor * Get-ReplPublisherMonitor * Get-ReplScript * Get-ReplServer * Get-ReplSubscriberSubscription * Get-ReplSubscription * Get-ReplTransPendingCommandInfo * New-ReplMergePublication * New-ReplScriptOptions * New-ReplTransPublication * Get-GroupUser * Get-ShowMbrs * New-ShowMbrs * Set-ShowMbrs * Out-SqlScript * Test-SqlScript * Add-SqlDatabase * Add-SqlDatabaseRole * Add-SqlDatabaseRoleMember * Add-SqlDataFile * Add-SqlFileGroup * Add-SqlLogFile * Add-SqlLogin * Add-SqlServerRoleMember * Add-SqlUser * Get-Sql * Get-SqlCheck * Get-SqlColumn * Get-SqlConnection * Get-SqlData * Get-SqlDatabase * Get-SqlDatabasePermission * Get-SqlDatabaseRole * Get-SqlDataFile * Get-SqlDefaultDir * Get-SqlEdition * Get-SqlErrorLog * Get-SqlForeignKey * Get-SqlIndex * Get-SqlIndexFragmentation * Get-SqlInformation_Schema.Columns * Get-SqlInformation_Schema.Routines * Get-SqlInformation_Schema.Tables * Get-SqlInformation_Schema.Views * Get-SqlLinkedServerLogin * Get-SqlLogFile * Get-SqlLogin * Get-SqlObjectPermission * Get-SqlPort * Get-SqlProcess * Get-SqlSchema * Get-SqlScripter * Get-SqlServer * Get-SqlServerPermission * Get-SqlServerRole * Get-SqlShowMbrs * Get-SqlStatistic * Get-SqlStoredProcedure * Get-SqlSynonym * Get-SqlSysDatabases * Get-SqlTable * Get-SqlTransaction * Get-SqlTrigger * Get-SqlUser * Get-SqlUserDefinedDataType * Get-SqlUserDefinedFunction * Get-SqlVersion * Get-SqlView * Invoke-SqlBackup * Invoke-SqlDatabaseCheck * Invoke-SqlIndexDefrag * Invoke-SqlIndexRebuild * Invoke-SqlRestore * New-SqlScriptingOptions * Remove-SqlDatabase * Remove-SqlDatabaseRole * Remove-SqlDatabaseRoleMember * Remove-SqlLogin * Remove-SqlServerRoleMember * Remove-SqlUser * Set-SqlData * Set-SqlDatabasePermission * Set-SqlObjectPermission * Set-SqlServerPermission * Update-SqlStatistic * Copy-ISItemFileToSQL * Copy-ISItemSQLToFile * Copy-ISItemSQLToSQL * Get-ISData * Get-ISItem * Get-ISPackage * Get-ISRunningPackage * Get-ISSqlConfigurationItem * New-ISApplication * New-ISItem * Remove-ISItem * Rename-ISItem * Set-ISConnectionString * Set-ISPackage * Test-ISPath]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://appdev.sqlpass.org/MeetingArchive/tabid/2005/Default.aspx">LiveMeeting session</a> for the AppDev Virtual Chapter of PASS yesterday I talked about building on top of tools that others had already built for you to use.  A great one for any DBA to use is the <a href="http://sqlpsx.codeplex.com/">SQL PowerShell Extensions</a> known as SQLPSX.  Even if you’ve never used PowerShell before you should take a look at this.  Heck even Sys Admins in shops that don’t have a DBA should have a look at this.  I have found the commands I have worked with very easy to use; even easier than T-SQL in some cases.</p>
<p><a href="http://sqlpsx.codeplex.com/releases/view/40773"><img style="display: inline; border-width: 0px;" title="SQLPSX" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/02/SQLPSX.png" border="0" alt="SQLPSX" width="335" height="70" /></a></p>
<p>After you <a href="http://sqlpsx.codeplex.com/releases/view/40773">download</a> the files and <a href="http://sqlpsx.codeplex.com/documentation">RTFM</a> you can then you can follow along on this next part.  Oh wait, first a little warning straight from <a href="http://blogs.msdn.com/buckwoody/archive/tags/PowerShell/default.aspx">Buck Woody</a>:</p>
<p><em><strong><span style="color: #800000;">Script Disclaimer, for people who need to be told this sort of thing: </span></strong></em><span style="color: #800000;"> </span></p>
<p><em><span style="color: #800000;">Never trust any script, including those that you find here, until you understand exactly what it does and how it will act on your systems. Always check the script on a test system or Virtual Machine, not a production system. All scripts on this site are performed by a professional stunt driver on a closed course. Your mileage may vary. Void where prohibited. Offer good for a limited time only. Keep out of reach of small children. Do not operate heavy machinery while using this script. If you experience blurry vision, indigestion or diarrhea during the operation of this script, see a physician immediately.</span> </em></p>
<p><span style="color: #0000ff;">get-module</span> <span style="color: #240084;">-listAvailable </span></p>
<p><span style="color: #240084;"><span style="color: #0000ff;">import-module</span> SQLServer</span></p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">Invoke-SqlBackup -sqlserver <span style="color: #006080;">"WINX64ULT7\Kilimanjaro"</span> -dbname <span style="color: #006080;">"AdventureWorks"</span> `</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">-filepath <span style="color: #006080;">"C:\Temp\AdventureWorks_db_$(((Get-Date).ToString("</span>yyyyMMddHHmm<span style="color: #006080;">"))).bak"</span></pre>
<p><!--CRLF--></p>
</div>
<div id="codeSnippetWrapper">
<p>Now this little script here (above) will backup a db for you and even include the current YearMonthDayHourMinute in the file string.  This one below will backup all of the non-system databases on your instance.  If you’re like me you’re thinking this doesn’t do anything that you can’t already do today with a maintenance plan.  That’s true and maybe I should have titled this post &#8220;Get <em>Something</em> Done with SQLPSX&#8221; but I will build on how you can leverage this more tomorrow.  For now, why don’t you add an AND clause only backup all the databases that start with ‘A’ <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">foreach</span> ($dbn <span style="color: #0000ff;">in</span> invoke-sqlcmd -query <span style="color: #006080;">"SELECT name  FROM sys.databases WHERE owner_sid !=0x01"</span> `</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">-database master -serverinstance WIN7\Kilimanjaro )</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">{</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">$k=<span style="color: #006080;">"C:\Temp\" + $($dbn.name) + "</span>_db_$(((Get-Date).ToString(<span style="color: #006080;">"yyyyMMddHHmm"</span>))).bak<span style="color: #006080;">"</span>WIN7\Kilimanjaro" -dbname $($dbn.name)  -filepath $k</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">$dbn; Invoke-SQLBackup -sqlserver "</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">}</pre>
<p><!--CRLF--></p>
</div>
</div>
<div id="codeSnippetWrapper">
<p>I’ve gone ahead and included the SQLPSX help items here.  Please see if there’s one that catches your eye and see if it might work for you.</p>
<p><a href="http://sqlpsx.appspot.com/Get-AgentAlert.htm">* Get-AgentAlert</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-AgentAlertCategory.htm">* Get-AgentAlertCategory</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-AgentJob.htm">* Get-AgentJob</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-AgentJobHistory.htm">* Get-AgentJobHistory</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-AgentJobSchedule.htm">* Get-AgentJobSchedule</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-AgentJobServer.htm">* Get-AgentJobServer</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-AgentJobStep.htm">* Get-AgentJobStep</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-AgentOperator.htm">* Get-AgentOperator</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-AgentOperatorCategory.htm">* Get-AgentOperatorCategory</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-AgentProxyAccount.htm">* Get-AgentProxyAccount</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-AgentSchedule.htm">* Get-AgentSchedule</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-AgentTargetServer.htm">* Get-AgentTargetServer</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-AgentTargetServerGroup.htm">* Get-AgentTargetServerGroup</a></p>
<p><a href="http://sqlpsx.appspot.com/Set-AgentJobHistoryFilter.htm">* Set-AgentJobHistoryFilter</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-ReplArticle.htm">* Get-ReplArticle</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-ReplEnumLogReaderAgent.htm">* Get-ReplEnumLogReaderAgent</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-ReplEnumPublications.htm">* Get-ReplEnumPublications</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-ReplEnumPublications2.htm">* Get-ReplEnumPublications2</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-ReplEnumSnapshotAgent.htm">* Get-ReplEnumSnapshotAgent</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-ReplEnumSubscriptions.htm">* Get-ReplEnumSubscriptions</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-ReplEnumSubscriptions2.htm">* Get-ReplEnumSubscriptions2</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-ReplLightPublication.htm">* Get-ReplLightPublication</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-ReplMonitor.htm">* Get-ReplMonitor</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-ReplPublication.htm">* Get-ReplPublication</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-ReplPublicationMonitor.htm">* Get-ReplPublicationMonitor</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-ReplPublisherMonitor.htm">* Get-ReplPublisherMonitor</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-ReplScript.htm">* Get-ReplScript</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-ReplServer.htm">* Get-ReplServer</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-ReplSubscriberSubscription.htm">* Get-ReplSubscriberSubscription</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-ReplSubscription.htm">* Get-ReplSubscription</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-ReplTransPendingCommandInfo.htm">* Get-ReplTransPendingCommandInfo</a></p>
<p><a href="http://sqlpsx.appspot.com/New-ReplMergePublication.htm">* New-ReplMergePublication</a></p>
<p><a href="http://sqlpsx.appspot.com/New-ReplScriptOptions.htm">* New-ReplScriptOptions</a></p>
<p><a href="http://sqlpsx.appspot.com/New-ReplTransPublication.htm">* New-ReplTransPublication</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-GroupUser.htm">* Get-GroupUser</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-ShowMbrs.htm">* Get-ShowMbrs</a></p>
<p><a href="http://sqlpsx.appspot.com/New-ShowMbrs.htm">* New-ShowMbrs</a></p>
<p><a href="http://sqlpsx.appspot.com/Set-ShowMbrs.htm">* Set-ShowMbrs</a></p>
<p><a href="http://sqlpsx.appspot.com/Out-SqlScript.htm">* Out-SqlScript</a></p>
<p><a href="http://sqlpsx.appspot.com/Test-SqlScript.htm">* Test-SqlScript</a></p>
<p><a href="http://sqlpsx.appspot.com/Add-SqlDatabase.htm">* Add-SqlDatabase</a></p>
<p><a href="http://sqlpsx.appspot.com/Add-SqlDatabaseRole.htm">* Add-SqlDatabaseRole</a></p>
<p><a href="http://sqlpsx.appspot.com/Add-SqlDatabaseRoleMember.htm">* Add-SqlDatabaseRoleMember</a></p>
<p><a href="http://sqlpsx.appspot.com/Add-SqlDataFile.htm">* Add-SqlDataFile</a></p>
<p><a href="http://sqlpsx.appspot.com/Add-SqlFileGroup.htm">* Add-SqlFileGroup</a></p>
<p><a href="http://sqlpsx.appspot.com/Add-SqlLogFile.htm">* Add-SqlLogFile</a></p>
<p><a href="http://sqlpsx.appspot.com/Add-SqlLogin.htm">* Add-SqlLogin</a></p>
<p><a href="http://sqlpsx.appspot.com/Add-SqlServerRoleMember.htm">* Add-SqlServerRoleMember</a></p>
<p><a href="http://sqlpsx.appspot.com/Add-SqlUser.htm">* Add-SqlUser</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-Sql.htm">* Get-Sql</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlCheck.htm">* Get-SqlCheck</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlColumn.htm">* Get-SqlColumn</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlConnection.htm">* Get-SqlConnection</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlData.htm">* Get-SqlData</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlDatabase.htm">* Get-SqlDatabase</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlDatabasePermission.htm">* Get-SqlDatabasePermission</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlDatabaseRole.htm">* Get-SqlDatabaseRole</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlDataFile.htm">* Get-SqlDataFile</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlDefaultDir.htm">* Get-SqlDefaultDir</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlEdition.htm">* Get-SqlEdition</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlErrorLog.htm">* Get-SqlErrorLog</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlForeignKey.htm">* Get-SqlForeignKey</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlIndex.htm">* Get-SqlIndex</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlIndexFragmentation.htm">* Get-SqlIndexFragmentation</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlInformation_Schema.Columns.htm">* Get-SqlInformation_Schema.Columns</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlInformation_Schema.Routines.htm">* Get-SqlInformation_Schema.Routines</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlInformation_Schema.Tables.htm">* Get-SqlInformation_Schema.Tables</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlInformation_Schema.Views.htm">* Get-SqlInformation_Schema.Views</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlLinkedServerLogin.htm">* Get-SqlLinkedServerLogin</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlLogFile.htm">* Get-SqlLogFile</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlLogin.htm">* Get-SqlLogin</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlObjectPermission.htm">* Get-SqlObjectPermission</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlPort.htm">* Get-SqlPort</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlProcess.htm">* Get-SqlProcess</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlSchema.htm">* Get-SqlSchema</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlScripter.htm">* Get-SqlScripter</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlServer.htm">* Get-SqlServer</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlServerPermission.htm">* Get-SqlServerPermission</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlServerRole.htm">* Get-SqlServerRole</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlShowMbrs.htm">* Get-SqlShowMbrs</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlStatistic.htm">* Get-SqlStatistic</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlStoredProcedure.htm">* Get-SqlStoredProcedure</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlSynonym.htm">* Get-SqlSynonym</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlSysDatabases.htm">* Get-SqlSysDatabases</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlTable.htm">* Get-SqlTable</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlTransaction.htm">* Get-SqlTransaction</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlTrigger.htm">* Get-SqlTrigger</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlUser.htm">* Get-SqlUser</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlUserDefinedDataType.htm">* Get-SqlUserDefinedDataType</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlUserDefinedFunction.htm">* Get-SqlUserDefinedFunction</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlVersion.htm">* Get-SqlVersion</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-SqlView.htm">* Get-SqlView</a></p>
<p><a href="http://sqlpsx.appspot.com/Invoke-SqlBackup.htm">* Invoke-SqlBackup</a></p>
<p><a href="http://sqlpsx.appspot.com/Invoke-SqlDatabaseCheck.htm">* Invoke-SqlDatabaseCheck</a></p>
<p><a href="http://sqlpsx.appspot.com/Invoke-SqlIndexDefrag.htm">* Invoke-SqlIndexDefrag</a></p>
<p><a href="http://sqlpsx.appspot.com/Invoke-SqlIndexRebuild.htm">* Invoke-SqlIndexRebuild</a></p>
<p><a href="http://sqlpsx.appspot.com/Invoke-SqlRestore.htm">* Invoke-SqlRestore</a></p>
<p><a href="http://sqlpsx.appspot.com/New-SqlScriptingOptions.htm">* New-SqlScriptingOptions</a></p>
<p><a href="http://sqlpsx.appspot.com/Remove-SqlDatabase.htm">* Remove-SqlDatabase</a></p>
<p><a href="http://sqlpsx.appspot.com/Remove-SqlDatabaseRole.htm">* Remove-SqlDatabaseRole</a></p>
<p><a href="http://sqlpsx.appspot.com/Remove-SqlDatabaseRoleMember.htm">* Remove-SqlDatabaseRoleMember</a></p>
<p><a href="http://sqlpsx.appspot.com/Remove-SqlLogin.htm">* Remove-SqlLogin</a></p>
<p><a href="http://sqlpsx.appspot.com/Remove-SqlServerRoleMember.htm">* Remove-SqlServerRoleMember</a></p>
<p><a href="http://sqlpsx.appspot.com/Remove-SqlUser.htm">* Remove-SqlUser</a></p>
<p><a href="http://sqlpsx.appspot.com/Set-SqlData.htm">* Set-SqlData</a></p>
<p><a href="http://sqlpsx.appspot.com/Set-SqlDatabasePermission.htm">* Set-SqlDatabasePermission</a></p>
<p><a href="http://sqlpsx.appspot.com/Set-SqlObjectPermission.htm">* Set-SqlObjectPermission</a></p>
<p><a href="http://sqlpsx.appspot.com/Set-SqlServerPermission.htm">* Set-SqlServerPermission</a></p>
<p><a href="http://sqlpsx.appspot.com/Update-SqlStatistic.htm">* Update-SqlStatistic</a></p>
<p><a href="http://sqlpsx.appspot.com/Copy-ISItemFileToSQL.htm">* Copy-ISItemFileToSQL</a></p>
<p><a href="http://sqlpsx.appspot.com/Copy-ISItemSQLToFile.htm">* Copy-ISItemSQLToFile</a></p>
<p><a href="http://sqlpsx.appspot.com/Copy-ISItemSQLToSQL.htm">* Copy-ISItemSQLToSQL</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-ISData.htm">* Get-ISData</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-ISItem.htm">* Get-ISItem</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-ISPackage.htm">* Get-ISPackage</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-ISRunningPackage.htm">* Get-ISRunningPackage</a></p>
<p><a href="http://sqlpsx.appspot.com/Get-ISSqlConfigurationItem.htm">* Get-ISSqlConfigurationItem</a></p>
<p><a href="http://sqlpsx.appspot.com/New-ISApplication.htm">* New-ISApplication</a></p>
<p><a href="http://sqlpsx.appspot.com/New-ISItem.htm">* New-ISItem</a></p>
<p><a href="http://sqlpsx.appspot.com/Remove-ISItem.htm">* Remove-ISItem</a></p>
<p><a href="http://sqlpsx.appspot.com/Rename-ISItem.htm">* Rename-ISItem</a></p>
<p><a href="http://sqlpsx.appspot.com/Set-ISConnectionString.htm">* Set-ISConnectionString</a></p>
<p><a href="http://sqlpsx.appspot.com/Set-ISPackage.htm">* Set-ISPackage</a></p>
<p><a href="http://sqlpsx.appspot.com/Test-ISPath.htm">* Test-ISPath</a></p>
</div>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://sqlvariant.com/wordpress/index.php/2010/02/get-more-done-with-sqlpsx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQLServer:\SQL\Databases\Tables&gt; Dir</title>
		<link>http://sqlvariant.com/wordpress/index.php/2010/02/sqlserversqldatabasestables-dir/</link>
		<comments>http://sqlvariant.com/wordpress/index.php/2010/02/sqlserversqldatabasestables-dir/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 13:40:07 +0000</pubDate>
		<dc:creator>Aaron Nelson</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[ISE]]></category>
		<category><![CDATA[PSSnapin]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SSMS]]></category>

		<guid isPermaLink="false">http://sqlvariant.com/wordpress/?p=492</guid>
		<description><![CDATA[Getting started talking to your SQL Servers in the PowerShell 2.0 ISE By now hopefully you’ve noticed that SQL Server 2008 comes with PowerShell all over the place.  Just about anything you click on in Object Explorer has “Start PowerShell” and you can even execute PowerShell steps in SQL Agent Jobs.  You may be wondering why on Earth you would want to “Start PowerShell” in the first place.  I’ll show you one thing today and then expand on that in later blog posts but today I wanted to tell you how to run PowerShell in something a little more organized than a command prompt window.  The first thing I’d like you to do is open up SSMS, connect to an instance and Right-Click the Databases folder &#62; then select Start PowerShell.  A command prompt window should open up and from there you can talk to your SQL Server instance as if was a drive on your machine: The SQLPS window that just opened up is PowerShell 1.0 with a special ‘expansion pack’ that allows it to talk to SQL Server in a way that PowerShell alone can’t.  So now that we’ve got that covered I want to show you how to do the same thing in PowerShell 2.0’s ISE.  Go to Start &#62; All Programs &#62; Accessories &#62; Windows PowerShell &#62; Windows PowerShell ISE Copy the code from the bottom and step through it like I did in this picture.  When you’re done you will be able to drill down to tables like they were just folders directories on your hard drive.  If you aren’t running Windows 7 (upgrade already!) check this post and see if you’re operating system is eligible. When you get to the part where you do “get-psdrive” for the second time you should now see the SQL Server on your local machine.  If you haven’t figured out yet, this is only going to work if you have SQL Server installed on your local machine.  #Before get-psdrive #Snapins that are running get-pssnapin #Snapins that you can load get-pssnapin -registered #Go ahead and add the SQL Snapins add-pssnapin SqlServerCmdletSnapin100 add-pssnapin SqlServerProviderSnapin100 #New Resource get-psdrive #What can we do with that? cd SQLSERVER:\SQL\YourComputerName\YourInstanceName\DATABASES\ADVENTUREWORKS\TABLES Now that we have done all of that we can do something that I have seen mentioned several places but I think that Allen White&#8217;s blog post explains it the best (here&#8217;s my version of it).  You can now create a variable and populate it with one the DDL structures in your database and from there generate a Create script for it like so: $PTH = get-item Production.TransactionHistory $PTH.Script() Your output should look something like this: PS SQLSERVER:\sql\WIN7\DATABASES\ADVENTUREWORKS\TABLES&#62; $PTH = get-item Production.TransactionHistory $PTH.Script() SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON CREATE TABLE [Production].[TransactionHistory](  [TransactionID] [int] IDENTITY(100000,1) NOT NULL,  [ProductID] [int] NOT NULL,  [ReferenceOrderID] [int] NOT NULL,  [ReferenceOrderLineID] [int] NOT NULL,  [TransactionDate] [datetime] NOT NULL,  [TransactionType] [nchar](1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,  [Quantity] [int] NOT NULL,  [ActualCost] [money] NOT NULL,  [ModifiedDate] [datetime] NOT NULL ) ON [PRIMARY] And that’s it for this edition of how to do something when you open up the PowerShell 2.0 ISE.  Next we’ll do something more useful I promise.]]></description>
			<content:encoded><![CDATA[<h5><span style="color: #000080;">Getting started talking to your SQL Servers in the PowerShell 2.0 ISE</span></h5>
<p>By now hopefully you’ve noticed that SQL Server 2008 comes with PowerShell all over the place.  Just about anything you click on in Object Explorer has “Start PowerShell” and you can even execute PowerShell steps in SQL Agent Jobs. </p>
<p>You may be wondering why on Earth you would <span style="text-decoration: underline;"><em>want</em></span> to “Start PowerShell” in the first place.  I’ll show you one thing today and then expand on that in later blog posts but today I wanted to tell you how to run PowerShell in something a little more organized than a command prompt window.  The first thing I’d like you to do is open up SSMS, connect to an instance and Right-Click the Databases folder &gt; then select Start PowerShell.  A command prompt window should open up and from there you can talk to your SQL Server instance as if was a drive on your machine:</p>
<p><a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/02/LaunchSQLPS.png"><img style="display: inline; border: 0px;" title="LaunchSQLPS" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/02/LaunchSQLPS_thumb.png" border="0" alt="LaunchSQLPS" width="677" height="293" /></a></p>
<p>The SQLPS window that just opened up is PowerShell 1.0 with a special ‘expansion pack’ that allows it to talk to SQL Server in a way that PowerShell alone can’t.  So now that we’ve got that covered I want to show you how to do the same thing in PowerShell 2.0’s ISE. </p>
<p>Go to Start &gt; All Programs &gt; Accessories &gt; Windows PowerShell &gt; Windows PowerShell ISE</p>
<p>Copy the code from the bottom and step through it like I did in this picture.  When you’re done you will be able to drill down to tables like they were just <span style="text-decoration: line-through;">folders</span> directories on your hard drive.  If you aren’t running Windows 7 (upgrade already!) check <a href="http://feedproxy.google.com/~r/Sqlvariations/~3/U1ZcyyS0S5M/" target="_blank">this post</a> and see if you’re operating system is eligible.</p>
<p><a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/02/ISE_SQL.png"><img style="display: inline; border: 0px;" title="ISE_SQL" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/02/ISE_SQL_thumb.png" border="0" alt="ISE_SQL" width="669" height="675" /></a></p>
<p>When you get to the part where you do “<span style="color: #0000ff;">get-psdrive</span>” for the second time you should now see the SQL Server on your local machine.  If you haven’t figured out yet, this is only going to work if you have SQL Server installed on your local machine. </p>
<p><span style="font-family: &amp;amp;amp; color: #006600; mso-bidi-font-family: aharoni;">#Before</span><span style="font-family: &amp;amp;amp; mso-bidi-font-family: aharoni;"><br />
<span style="color: blue;">get-psdrive</span> </span></p>
<p><span style="font-family: &amp;amp;amp; color: #006600; mso-bidi-font-family: aharoni;">#Snapins that are running</span><span style="font-family: &amp;amp;amp; mso-bidi-font-family: aharoni;"><br />
<span style="color: blue;">get-pssnapin </span><br />
<span style="color: #006600;">#Snapins that you can load</span><br />
<span style="color: blue;">get-pssnapin </span><span style="color: #1f497d; mso-themecolor: text2; mso-style-textfill-fill-color: #1f497d; mso-style-textfill-fill-themecolor: text2; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: lumm=75000;">-registered </span></span></p>
<p><span style="font-family: &amp;amp;amp; color: #006600; mso-bidi-font-family: aharoni;">#Go ahead and add the SQL Snapins</span><span style="font-family: &amp;amp;amp; color: #003300; mso-bidi-font-family: aharoni;"><br />
</span><span style="font-family: &amp;amp;amp; color: blue; mso-bidi-font-family: aharoni;">add-pssnapin </span><span style="font-family: &amp;amp;amp; color: #7030a0; mso-bidi-font-family: aharoni;">SqlServerCmdletSnapin100</span><span style="font-family: &amp;amp;amp; mso-bidi-font-family: aharoni;"><br />
<span style="color: blue;">add-pssnapin </span><span style="color: #7030a0;">SqlServerProviderSnapin100 </span></span></p>
<p><span style="font-family: &amp;amp;amp; color: #006600; mso-bidi-font-family: aharoni;">#New Resource</span><span style="font-family: &amp;amp;amp; mso-bidi-font-family: aharoni;"><br />
<span style="color: blue;">get-psdrive </span></span></p>
<p><span style="font-family: &amp;amp;amp; color: #006600; mso-bidi-font-family: aharoni;">#What can we do with that?</span><span style="font-family: &amp;amp;amp; mso-bidi-font-family: aharoni;"><br />
<span style="color: blue;">cd</span> <span style="color: #7030a0;">SQLSERVER:\SQL\</span><span style="color: red;">YourComputerName</span><span style="color: #7030a0;">\</span><span style="color: red;">YourInstanceName</span><span style="color: #7030a0;">\DATABASES\ADVENTUREWORKS\TABLES</span></span></p>
<p>Now that we have done all of that we can do something that I have seen mentioned several places but I think that <a href="http://sqlblog.com/blogs/allen_white/archive/2009/09/16/browse-and-script.aspx">Allen White&#8217;s blog post</a> explains it the best (here&#8217;s my version of it).  You can now create a variable and populate it with one the DDL structures in your database and from there generate a Create script for it like so:</p>
<p><span style="color: #ff0000;">$PTH</span> <span style="color: #808080;">=</span> <span style="color: #0000ff;">get-item</span> <span style="color: #800080;">Production.TransactionHistory</span><br />
<span style="color: #ff0000;">$PTH</span><span style="color: #808080;">.</span>Script()</p>
<p><span style="text-decoration: underline;">Your output should look something like this:</span><br />
PS SQLSERVER:\sql\WIN7\DATABASES\ADVENTUREWORKS\TABLES&gt; $PTH = get-item Production.TransactionHistory<br />
$PTH.Script()<br />
SET ANSI_NULLS ON<br />
SET QUOTED_IDENTIFIER ON<br />
CREATE TABLE [Production].[TransactionHistory](<br />
 [TransactionID] [int] IDENTITY(100000,1) NOT NULL,<br />
 [ProductID] [int] NOT NULL,<br />
 [ReferenceOrderID] [int] NOT NULL,<br />
 [ReferenceOrderLineID] [int] NOT NULL,<br />
 [TransactionDate] [datetime] NOT NULL,<br />
 [TransactionType] [nchar](1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,<br />
 [Quantity] [int] NOT NULL,<br />
 [ActualCost] [money] NOT NULL,<br />
 [ModifiedDate] [datetime] NOT NULL<br />
) ON [PRIMARY]</p>
<p>And that’s it for this edition of how to do something when you open up the PowerShell 2.0 ISE.  Next we’ll do something more useful I promise.</p>
]]></content:encoded>
			<wfw:commentRss>http://sqlvariant.com/wordpress/index.php/2010/02/sqlserversqldatabasestables-dir/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Filtered Indexes: The Conversation</title>
		<link>http://sqlvariant.com/wordpress/index.php/2010/02/filtered-indexes-the-conversation/</link>
		<comments>http://sqlvariant.com/wordpress/index.php/2010/02/filtered-indexes-the-conversation/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 12:48:57 +0000</pubDate>
		<dc:creator>Aaron Nelson</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Filtered Indexes]]></category>
		<category><![CDATA[Pipeline]]></category>
		<category><![CDATA[SQL Server 2008]]></category>

		<guid isPermaLink="false">http://sqlvariant.com/wordpress/?p=527</guid>
		<description><![CDATA[A few months back as one of my very first blog posts I showed off some functionality that I had learned in Bruce Payette’s book “PowerShell In Action”  (Coincidentally a new update to the MEAP for the Second Edition was released tonight).  I showed how it was not too difficult to Archive the wisdom of Paul Randal’s Tweets for the PASS Summit.  Tonight I had a conversation with Adam Machanic and wanted to save that off as well.  I got an idea when watching Allen White talk about Filtered Indexes on Tuesday (insert obligatory AppDev VC of PASS plug here: &#8220;Allen White Presents:  SQL Server Indexing&#8220; ).  I have a situation where I have six or seven columns that I want to index but I would prefer to only index the rows that have been created after the first 90 days.  After the first 90 days our people just don&#8217;t query those columns anywhere near as much.  My original idea was to create a filtered index on the &#8216;CreationDate&#8217; column and then INCLUDE the 5 or 6 other columns that tend to get queried heavily during those first 90 days.  I also have some flash drives on my SAN that I want to use for these indexes but the drives aren&#8217;t very big and if I create the indexes across the whole table they will use up a lot of space and only a fraction of the entire index would get hit hard (very hard).  The conversation that transpired between Adam and I was a great dive into the topic of Filtered Indexes for me; I&#8217;ve worked with them before but I&#8217;ve never tried this particular scenario before.  Adam said that this convo gave him idea to blog about.  I can&#8217;t wait to see it.  Until then you can read up on what we discussed below. Having worked with PowerShell for several more months now I have learned a few things and was able to implement them on the fly to make this process even easier.  This time instead of using the format options I just select-ed the columns that I wanted to keep out of the Pipeline and exported it to CSV.  The process of favorite&#8217;ing the individual tweets in the conversation is still a manual process; but I&#8217;m sure that a few more weeks of PowerShell learning will fix that.  Here’s the code that I used tonight: ([xml] (new-object net.webclient).DownloadString(“http://twitter.com/favorites/76699854.rss”)).rss.channel.item &#124; select description, pubDate, link &#124; Export-CSV c:\Temp\FilteredIndexes.CSV And now, you can read the conversation that I had with Adam Machanic without all the clutter of the other tweets during that time period: description pubDate link SQLvariant: Listening to Allen White speak about Indexing for the AppDev VC of #SQLPASS http://bit.ly/bgM06y Tue, 09 Feb 2010 17:03:37 http://twitter.com/SQLvariant/statuses/8862223289 MidnightDBA: I&#8217;m behind the times, work on SQL05. Can&#8217;t wait to work w/sql 08 professionally, filtered indexes are awesomesauce. Tue, 09 Feb 2010 17:10:55 http://twitter.com/MidnightDBA/statuses/8862493660 AdamMachanic: @MidnightDBA They&#8217;re not as great in practice as they seem when you first learn about them, IMO. Lots of limitations and few use cases Tue, 09 Feb 2010 17:18:54 http://twitter.com/AdamMachanic/statuses/8862783462 SQLvariant: @AdamMachanic Well then you should probably tell Allen to quit giving us good ideas on how to use them Tue, 09 Feb 2010 17:24:34 http://twitter.com/SQLvariant/statuses/8862986987 AdamMachanic: @SQLvariant Such as? Tue, 09 Feb 2010 17:49:13 http://twitter.com/AdamMachanic/statuses/8863863635 SQLvariant: @AdamMachanic Only indexing the last quarter&#8217;s worth of data. Tue, 09 Feb 2010 17:59:54 http://twitter.com/SQLvariant/statuses/8864239382 SQLvariant: @AdamMachanic &#8230; I realize that table partitioning would normally present a better solution but I can still see some useful scenarios Tue, 09 Feb 2010 18:01:14 http://twitter.com/SQLvariant/statuses/8864294018 AdamMachanic: @SQLvariant I was hoping you would send me a link or two Tue, 09 Feb 2010 18:01:43 http://twitter.com/AdamMachanic/statuses/8864311604 AdamMachanic: @SQLvariant Hmm, I&#8217;ve been thinking about only indexing last qtr w/ filtered index, and that strikes me as a really bad idea. Not only 1/? Tue, 09 Feb 2010 20:25:45 http://twitter.com/AdamMachanic/statuses/8869378189 AdamMachanic: @SQLvariant will you have to hardcode a date in the index&#8211;meaning that you&#8217;ll have to keep it up to date somehow (manually? a process?) 2/? Tue, 09 Feb 2010 20:26:15 http://twitter.com/AdamMachanic/statuses/8869395660 AdamMachanic: @SQLvariant your queries on the last qtr will also have to include that date, hardcoded, or else your plans won&#8217;t use the index 3/? Tue, 09 Feb 2010 20:27:32 http://twitter.com/AdamMachanic/statuses/8869441985 AdamMachanic: @SQLvariant ex. SELECT * FROM tbl WHERE dt &#38;gt; @dt &#8212; would have to either not use the idx or recompile every time 4/4 Tue, 09 Feb 2010 20:29:06 http://twitter.com/AdamMachanic/statuses/8869496991 AdamMachanic: @SQLvariant Any thoughts on my comments yesterday regarding filtered indexes and indexing for the last quarter? Thu, 11 Feb 2010 01:04:53 http://twitter.com/AdamMachanic/statuses/8928304859 SQLvariant: @AdamMachanic yes. Chewing on those now. (Just read them a few minutes ago.) Thu, 11 Feb 2010 01:05:39 http://twitter.com/SQLvariant/statuses/8928338093 SQLvariant: @AdamMachanic So on 4/4: Were you saying rebuild every time you run the query? or rebuild query every time you rebuild the index? Thu, 11 Feb 2010 01:06:55 http://twitter.com/SQLvariant/statuses/8928391399 AdamMachanic: @SQLvariant Your query has to have literals for it to use the index&#8211;I tried. It might work w/ the RECOMPILE hint but I didn&#8217;t test that Thu, 11 Feb 2010 01:41:02 http://twitter.com/AdamMachanic/statuses/8929858439 AdamMachanic: @SQLvariant So rebuild query every time you rebuild the index. And you have to have more than one query: One for most recent quarter, 1/2 Thu, 11 Feb 2010 01:41:35 http://twitter.com/AdamMachanic/statuses/8929881524 AdamMachanic: @SQLvariant &#8230; and one for all of history &#8230; and logic in your app to choose the right query. PITA! 2/2 Thu, 11 Feb 2010 01:41:54 http://twitter.com/AdamMachanic/statuses/8929894671 SQLvariant: @AdamMachanic If I only have to rebuild the queries every time that I rebuild the index that&#8217;s very doable. Thu, 11 Feb 2010 01:43:12 http://twitter.com/SQLvariant/statuses/8929949599 SQLvariant: @AdamMachanic Actually&#8230;. We already have more complex logic our app. Just put it there last month, before it was doing full scans. Thu, 11 Feb 2010 01:44:13 http://twitter.com/SQLvariant/statuses/8929992415 AdamMachanic: @SQLvariant And you want to have to re-create your indexes every quarter? Not simply run ALTER REBUILD, but actually re-create Thu, 11 Feb 2010 01:44:17 http://twitter.com/AdamMachanic/statuses/8929995070 AdamMachanic: @SQLvariant And maintain every query in the system that might rely on that index, and make sure the app chooses the right query every time? Thu, 11 Feb 2010 01:44:46 http://twitter.com/AdamMachanic/statuses/8930015395 SQLvariant: @AdamMachanic Why it was doing full scans is a long story itself. But this is definitely giving me ideas to test out. Thu, 11 Feb 2010 01:45:08 http://twitter.com/SQLvariant/statuses/8930031641 AdamMachanic: @SQLvariant But a normal index could be used instead, without all of this maintenance overhead, at the cost of storage space Thu, 11 Feb 2010 01:45:36 http://twitter.com/AdamMachanic/statuses/8930051825 SQLvariant: @AdamMachanic Not rebuild them every quarter, rebuild them every weekend to reflect the last 13 weeks. Thu, 11 Feb 2010 01:46:05 http://twitter.com/SQLvariant/statuses/8930072522 SQLvariant: @AdamMachanic Right, see that&#8217;s the thing. I&#8217;m pondering this because I want to save on storage. Thu, 11 Feb 2010 01:47:02 http://twitter.com/SQLvariant/statuses/8930112826 AdamMachanic: @SQLvariant Even worse! Thu, 11 Feb 2010 01:47:05 http://twitter.com/AdamMachanic/statuses/8930115641 SQLvariant: @AdamMachanic Here&#8217;s my situation: I have a handful of Flash drives for my @EMCCLARiiON but they&#8217;re not enough to store all of my indexes. Thu, 11 Feb 2010 01:48:09 http://twitter.com/SQLvariant/statuses/8930161731 AdamMachanic: @SQLvariant I don&#8217;t think the chance of screwing up and missing a query is worth the benefit&#8230; unless you use a macro system to 1/2 Thu, 11 Feb 2010 01:48:35 http://twitter.com/AdamMachanic/statuses/8930180307 SQLvariant: @AdamMachanic &#8230;2/2 but if some of the indexes were filtered indexes they could all fit. Thu, 11 Feb 2010 01:48:51 http://twitter.com/SQLvariant/statuses/8930191531 AdamMachanic: @SQLvariant maintain the queries&#8230; hmm&#8230; could be a use case for this: http://datamanipulation.net/tsqlmacro/ Thu, 11 Feb 2010 01:49:09 http://twitter.com/AdamMachanic/statuses/8930204248 SQLvariant: @AdamMachanic Are you suggesting the TSQLMacro for rebuilding the queries or something? Thu, 11 Feb 2010 01:50:48 http://twitter.com/SQLvariant/statuses/8930274857 AdamMachanic: @SQLvariant But are they filtered for something like &#8220;last quarter&#8221; or something more static? I&#8217;m not saying filtered indexes are bad, 1/2 Thu, 11 Feb 2010 01:51:12 http://twitter.com/AdamMachanic/statuses/8930292580 AdamMachanic: @SQLvariant but rather that it&#8217;s dangerous and tricky to properly filter on a moving target 2/2 Thu, 11 Feb 2010 01:51:32 http://twitter.com/AdamMachanic/statuses/8930307008 AdamMachanic: @SQLvariant Right, you could create a macro for the dynamic predicate, then just re-process all of your procs along w/ the queries Thu, 11 Feb 2010 01:51:59 http://twitter.com/AdamMachanic/statuses/8930325441 AdamMachanic: @SQLvariant As a matter of fact, I&#8217;m about to release a new version of the framework, and this could be interesting to add to the docs! Thu, 11 Feb 2010 01:52:30 http://twitter.com/AdamMachanic/statuses/8930348061 SQLvariant: @AdamMachanic I have a very static use pattern for records in the last 90 days; after that, they don&#8217;t get queried as much. Thu, 11 Feb 2010 01:53:18 http://twitter.com/SQLvariant/statuses/8930382479 SQLvariant: @AdamMachanic Oh. Well I was just going to do it with PowerShell. We have a TSQL query that rebuilds them now (a bit manual though). Thu, 11 Feb 2010 01:54:46 http://twitter.com/SQLvariant/statuses/8930445413 AdamMachanic: @SQLvariant That rebuilds queries? You&#8217;re already doing that work? Thu, 11 Feb 2010 01:55:34 http://twitter.com/AdamMachanic/statuses/8930479667 SQLvariant: @AdamMachanic &#8230; Sorry, re-phrase: We already have a TSQL Query that rebuilds other things based on current month. Thu, 11 Feb 2010 01:55:36 http://twitter.com/SQLvariant/statuses/8930481170 AdamMachanic: @SQLvariant So what are you doing now? Maintaining a separate table for the previous 90 days worth of data? Thu, 11 Feb 2010 01:56:27 http://twitter.com/AdamMachanic/statuses/8930517242 SQLvariant: @AdamMachanic um, kinda-sorta. But it&#8217;s for the B/I system, not for the relational system. Thu, 11 Feb 2010 01:57:55 http://twitter.com/SQLvariant/statuses/8930578819 AdamMachanic: @SQLvariant Seems like partitioning (as you mentioned yesterday) would be the easiest solution for the case you mentioned&#8230; if you have 1/2 Thu, 11 Feb 2010 02:00:06 http://twitter.com/AdamMachanic/statuses/8940513547 SQLvariant: @AdamMachanic I was already working on [...]]]></description>
			<content:encoded><![CDATA[<p>A few months back as one of my very first blog posts I showed off some functionality that I had learned in Bruce Payette’s book “<strong>PowerShell In Action</strong>”  (Coincidentally a new update to the <a href="http://bit.ly/axGHRP">MEAP for the <span style="color: #0000ff;">Second Edition</span></a><span style="color: #0000ff;"> </span>was released tonight).  I showed how it was not too difficult to <a href="http://feedproxy.google.com/~r/Sqlvariations/~3/0CP5AZlXtg8/">Archive the wisdom of Paul Randal’s Tweets for the PASS Summit</a>.  Tonight I had a conversation with Adam Machanic and wanted to save that off as well. </p>
<p>I got an idea when watching Allen White talk about Filtered Indexes on Tuesday (insert obligatory AppDev VC of PASS plug here: &#8220;<a href="http://bit.ly/c7sHa8"><strong>Allen White</strong> Presents:  <strong>SQL Server Indexing</strong></a>&#8220; ).  I have a situation where I have six or seven columns that I want to index but I would prefer to only index the rows that have been created after the first 90 days.  After the first 90 days our people just don&#8217;t query those columns anywhere near as much.  My original idea was to create a filtered index on the &#8216;CreationDate&#8217; column and then INCLUDE the 5 or 6 other columns that tend to get queried heavily during those first 90 days.  I also have some flash drives on my SAN that I want to use for these indexes but the drives aren&#8217;t very big and if I create the indexes across the whole table they will use up <span style="text-decoration: underline;">a lot</span> of space and only a fraction of the entire index would get hit hard (very hard). </p>
<p>The conversation that transpired between Adam and I was a great dive into the topic of Filtered Indexes for me; I&#8217;ve worked with them before but I&#8217;ve never tried this particular scenario before.  Adam said that this convo gave him idea to blog about.  I can&#8217;t wait to see it.  Until then you can read up on what we discussed below.<br />
<a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/02/adam_machanic.jpg"><img style="display: inline; border-width: 0px;" title="adam_machanic" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/02/adam_machanic_thumb.jpg" border="0" alt="adam_machanic" width="68" height="87" /></a></p>
<p>Having worked with PowerShell for several more months now I have learned a few things and was able to implement them on the fly to make this process even easier.  This time instead of using the format options I just <strong>select-</strong>ed the columns that I wanted to keep out of the <strong>Pipeline</strong> and exported it to CSV.  The process of favorite&#8217;ing the individual tweets in the conversation is still a manual process; but I&#8217;m sure that a few more weeks of PowerShell learning will fix that. </p>
<p>Here’s the code that I used tonight:</p>
<p>(<span style="color: #008080;">[xml]</span> (<span style="color: #0000ff;">new-object</span> <span style="color: #800080;">net.webclient</span>).DownloadString(<span style="color: #800000;">“</span><a href="http://twitter.com/favorites/76699854.rss”)).rss.channel.item"><span style="color: #800000;">http://twitter.com/favorites/76699854.rss</span></a><span style="color: #800000;">”<span style="color: #000000;">)).</span></span>rss.channel.item <span style="color: #888888;">|</span> <span style="color: #0000ff;">select</span> <span style="color: #800080;">description, pubDate, link</span> <span style="color: #888888;">|</span> <span style="color: #0000ff;">Export-CSV</span> <span style="color: #800080;">c:\Temp\FilteredIndexes.CSV</span></p>
<p>And now, you can read the conversation that I had with Adam Machanic without all the clutter of the other tweets during that time period:</p>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="1061"><strong>description</strong></td>
<td width="180"><strong>pubDate</strong></td>
<td width="64"><strong>link</strong></td>
</tr>
<tr>
<td>SQLvariant: Listening to Allen White speak about Indexing for the AppDev VC of #SQLPASS http://bit.ly/bgM06y</td>
<td>Tue, 09 Feb 2010 17:03:37</td>
<td>http://twitter.com/SQLvariant/statuses/8862223289</td>
</tr>
<tr>
<td>MidnightDBA: I&#8217;m behind the times, work on SQL05. Can&#8217;t wait to work w/sql 08 professionally, filtered indexes are awesomesauce.</td>
<td>Tue, 09 Feb 2010 17:10:55</td>
<td>http://twitter.com/MidnightDBA/statuses/8862493660</td>
</tr>
<tr>
<td>AdamMachanic: @MidnightDBA They&#8217;re not as great in practice as they seem when you first learn about them, IMO. Lots of limitations and few use cases</td>
<td>Tue, 09 Feb 2010 17:18:54</td>
<td>http://twitter.com/AdamMachanic/statuses/8862783462</td>
</tr>
<tr>
<td>SQLvariant: @AdamMachanic Well then you should probably tell Allen to quit giving us good ideas on how to use them <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </td>
<td>Tue, 09 Feb 2010 17:24:34</td>
<td>http://twitter.com/SQLvariant/statuses/8862986987</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant Such as?</td>
<td>Tue, 09 Feb 2010 17:49:13</td>
<td>http://twitter.com/AdamMachanic/statuses/8863863635</td>
</tr>
<tr>
<td>SQLvariant: @AdamMachanic Only indexing the last quarter&#8217;s worth of data.</td>
<td>Tue, 09 Feb 2010 17:59:54</td>
<td>http://twitter.com/SQLvariant/statuses/8864239382</td>
</tr>
<tr>
<td>SQLvariant: @AdamMachanic &#8230; I realize that table partitioning would normally present a better solution but I can still see some useful scenarios</td>
<td>Tue, 09 Feb 2010 18:01:14</td>
<td>http://twitter.com/SQLvariant/statuses/8864294018</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant I was hoping you would send me a link or two</td>
<td>Tue, 09 Feb 2010 18:01:43</td>
<td>http://twitter.com/AdamMachanic/statuses/8864311604</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant Hmm, I&#8217;ve been thinking about only indexing last qtr w/ filtered index, and that strikes me as a really bad idea. Not only 1/?</td>
<td>Tue, 09 Feb 2010 20:25:45</td>
<td>http://twitter.com/AdamMachanic/statuses/8869378189</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant will you have to hardcode a date in the index&#8211;meaning that you&#8217;ll have to keep it up to date somehow (manually? a process?) 2/?</td>
<td>Tue, 09 Feb 2010 20:26:15</td>
<td>http://twitter.com/AdamMachanic/statuses/8869395660</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant your queries on the last qtr will also have to include that date, hardcoded, or else your plans won&#8217;t use the index 3/?</td>
<td>Tue, 09 Feb 2010 20:27:32</td>
<td>http://twitter.com/AdamMachanic/statuses/8869441985</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant ex. SELECT * FROM tbl WHERE dt &amp;gt; @dt &#8212; would have to either not use the idx or recompile every time 4/4</td>
<td>Tue, 09 Feb 2010 20:29:06</td>
<td>http://twitter.com/AdamMachanic/statuses/8869496991</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant Any thoughts on my comments yesterday regarding filtered indexes and indexing for the last quarter?</td>
<td>Thu, 11 Feb 2010 01:04:53</td>
<td>http://twitter.com/AdamMachanic/statuses/8928304859</td>
</tr>
<tr>
<td>SQLvariant: @AdamMachanic yes. Chewing on those now. (Just read them a few minutes ago.)</td>
<td>Thu, 11 Feb 2010 01:05:39</td>
<td>http://twitter.com/SQLvariant/statuses/8928338093</td>
</tr>
<tr>
<td>SQLvariant: @AdamMachanic So on 4/4: Were you saying rebuild every time you run the query? or rebuild query every time you rebuild the index?</td>
<td>Thu, 11 Feb 2010 01:06:55</td>
<td>http://twitter.com/SQLvariant/statuses/8928391399</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant Your query has to have literals for it to use the index&#8211;I tried. It might work w/ the RECOMPILE hint but I didn&#8217;t test that</td>
<td>Thu, 11 Feb 2010 01:41:02</td>
<td>http://twitter.com/AdamMachanic/statuses/8929858439</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant So rebuild query every time you rebuild the index. And you have to have more than one query: One for most recent quarter, 1/2</td>
<td>Thu, 11 Feb 2010 01:41:35</td>
<td>http://twitter.com/AdamMachanic/statuses/8929881524</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant &#8230; and one for all of history &#8230; and logic in your app to choose the right query. PITA! 2/2</td>
<td>Thu, 11 Feb 2010 01:41:54</td>
<td>http://twitter.com/AdamMachanic/statuses/8929894671</td>
</tr>
<tr>
<td>SQLvariant: @AdamMachanic If I only have to rebuild the queries every time that I rebuild the index that&#8217;s very doable.</td>
<td>Thu, 11 Feb 2010 01:43:12</td>
<td>http://twitter.com/SQLvariant/statuses/8929949599</td>
</tr>
<tr>
<td>SQLvariant: @AdamMachanic Actually&#8230;. We already have more complex logic our app. Just put it there last month, before it was doing full scans.</td>
<td>Thu, 11 Feb 2010 01:44:13</td>
<td>http://twitter.com/SQLvariant/statuses/8929992415</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant And you want to have to re-create your indexes every quarter? Not simply run ALTER REBUILD, but actually re-create</td>
<td>Thu, 11 Feb 2010 01:44:17</td>
<td>http://twitter.com/AdamMachanic/statuses/8929995070</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant And maintain every query in the system that might rely on that index, and make sure the app chooses the right query every time?</td>
<td>Thu, 11 Feb 2010 01:44:46</td>
<td>http://twitter.com/AdamMachanic/statuses/8930015395</td>
</tr>
<tr>
<td>SQLvariant: @AdamMachanic Why it was doing full scans is a long story itself. But this is definitely giving me ideas to test out.</td>
<td>Thu, 11 Feb 2010 01:45:08</td>
<td>http://twitter.com/SQLvariant/statuses/8930031641</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant But a normal index could be used instead, without all of this maintenance overhead, at the cost of storage space</td>
<td>Thu, 11 Feb 2010 01:45:36</td>
<td>http://twitter.com/AdamMachanic/statuses/8930051825</td>
</tr>
<tr>
<td>SQLvariant: @AdamMachanic Not rebuild them every quarter, rebuild them every weekend to reflect the last 13 weeks.</td>
<td>Thu, 11 Feb 2010 01:46:05</td>
<td>http://twitter.com/SQLvariant/statuses/8930072522</td>
</tr>
<tr>
<td>SQLvariant: @AdamMachanic Right, see that&#8217;s the thing. I&#8217;m pondering this because I want to save on storage.</td>
<td>Thu, 11 Feb 2010 01:47:02</td>
<td>http://twitter.com/SQLvariant/statuses/8930112826</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant Even worse!</td>
<td>Thu, 11 Feb 2010 01:47:05</td>
<td>http://twitter.com/AdamMachanic/statuses/8930115641</td>
</tr>
<tr>
<td>SQLvariant: @AdamMachanic Here&#8217;s my situation: I have a handful of Flash drives for my @EMCCLARiiON but they&#8217;re not enough to store all of my indexes.</td>
<td>Thu, 11 Feb 2010 01:48:09</td>
<td>http://twitter.com/SQLvariant/statuses/8930161731</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant I don&#8217;t think the chance of screwing up and missing a query is worth the benefit&#8230; unless you use a macro system to 1/2</td>
<td>Thu, 11 Feb 2010 01:48:35</td>
<td>http://twitter.com/AdamMachanic/statuses/8930180307</td>
</tr>
<tr>
<td>SQLvariant: @AdamMachanic &#8230;2/2 but if some of the indexes were filtered indexes they could all fit.</td>
<td>Thu, 11 Feb 2010 01:48:51</td>
<td>http://twitter.com/SQLvariant/statuses/8930191531</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant maintain the queries&#8230; hmm&#8230; could be a use case for this: http://datamanipulation.net/tsqlmacro/</td>
<td>Thu, 11 Feb 2010 01:49:09</td>
<td>http://twitter.com/AdamMachanic/statuses/8930204248</td>
</tr>
<tr>
<td>SQLvariant: @AdamMachanic Are you suggesting the TSQLMacro for rebuilding the queries or something?</td>
<td>Thu, 11 Feb 2010 01:50:48</td>
<td>http://twitter.com/SQLvariant/statuses/8930274857</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant But are they filtered for something like &#8220;last quarter&#8221; or something more static? I&#8217;m not saying filtered indexes are bad, 1/2</td>
<td>Thu, 11 Feb 2010 01:51:12</td>
<td>http://twitter.com/AdamMachanic/statuses/8930292580</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant but rather that it&#8217;s dangerous and tricky to properly filter on a moving target 2/2</td>
<td>Thu, 11 Feb 2010 01:51:32</td>
<td>http://twitter.com/AdamMachanic/statuses/8930307008</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant Right, you could create a macro for the dynamic predicate, then just re-process all of your procs along w/ the queries</td>
<td>Thu, 11 Feb 2010 01:51:59</td>
<td>http://twitter.com/AdamMachanic/statuses/8930325441</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant As a matter of fact, I&#8217;m about to release a new version of the framework, and this could be interesting to add to the docs!</td>
<td>Thu, 11 Feb 2010 01:52:30</td>
<td>http://twitter.com/AdamMachanic/statuses/8930348061</td>
</tr>
<tr>
<td>SQLvariant: @AdamMachanic I have a very static use pattern for records in the last 90 days; after that, they don&#8217;t get queried as much.</td>
<td>Thu, 11 Feb 2010 01:53:18</td>
<td>http://twitter.com/SQLvariant/statuses/8930382479</td>
</tr>
<tr>
<td>SQLvariant: @AdamMachanic Oh. Well I was just going to do it with PowerShell. We have a TSQL query that rebuilds them now (a bit manual though).</td>
<td>Thu, 11 Feb 2010 01:54:46</td>
<td>http://twitter.com/SQLvariant/statuses/8930445413</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant That rebuilds queries? You&#8217;re already doing that work?</td>
<td>Thu, 11 Feb 2010 01:55:34</td>
<td>http://twitter.com/AdamMachanic/statuses/8930479667</td>
</tr>
<tr>
<td>SQLvariant: @AdamMachanic &#8230; Sorry, re-phrase: We already have a TSQL Query that rebuilds other things based on current month.</td>
<td>Thu, 11 Feb 2010 01:55:36</td>
<td>http://twitter.com/SQLvariant/statuses/8930481170</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant So what are you doing now? Maintaining a separate table for the previous 90 days worth of data?</td>
<td>Thu, 11 Feb 2010 01:56:27</td>
<td>http://twitter.com/AdamMachanic/statuses/8930517242</td>
</tr>
<tr>
<td>SQLvariant: @AdamMachanic um, kinda-sorta. But it&#8217;s for the B/I system, not for the relational system.</td>
<td>Thu, 11 Feb 2010 01:57:55</td>
<td>http://twitter.com/SQLvariant/statuses/8930578819</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant Seems like partitioning (as you mentioned yesterday) would be the easiest solution for the case you mentioned&#8230; if you have 1/2</td>
<td>Thu, 11 Feb 2010 02:00:06</td>
<td>http://twitter.com/AdamMachanic/statuses/8940513547</td>
</tr>
<tr>
<td>SQLvariant: @AdamMachanic I was already working on replacing that semi-automatic T-SQL process with a fully-automatic PowerShell script.</td>
<td>Thu, 11 Feb 2010 02:00:22</td>
<td>http://twitter.com/SQLvariant/statuses/8940528365</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant less than 20 years worth of data, you could even partition by week and it would be dead simple to maintain 2/2</td>
<td>Thu, 11 Feb 2010 02:00:25</td>
<td>http://twitter.com/AdamMachanic/statuses/8940530606</td>
</tr>
<tr>
<td>SQLvariant: @AdamMachanic Right. Because I can create indexes that are only on certain partitions right?</td>
<td>Thu, 11 Feb 2010 02:01:46</td>
<td>http://twitter.com/SQLvariant/statuses/8940593964</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant I don&#8217;t believe so, but you can put partitions on whatever filegroup you want and easily move them around at will, so if you 1/2</td>
<td>Thu, 11 Feb 2010 02:02:35</td>
<td>http://twitter.com/AdamMachanic/statuses/8940630194</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant had one partition per week you could slide the new week onto the flash drives and the old week off in two lines of code 2/2</td>
<td>Thu, 11 Feb 2010 02:03:01</td>
<td>http://twitter.com/AdamMachanic/statuses/8940648133</td>
</tr>
<tr>
<td>SQLvariant: @AdamMachanic Sorry, must be mixing SSAS aggregations. But I dont want to even backup the full indexes since I won&#8217;t really need all of them</td>
<td>Thu, 11 Feb 2010 02:06:24</td>
<td>http://twitter.com/SQLvariant/statuses/8940794933</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant No one will ever ask for old data? Or you just don&#8217;t care if the old data query takes 100x longer?</td>
<td>Thu, 11 Feb 2010 02:07:24</td>
<td>http://twitter.com/AdamMachanic/statuses/8940839200</td>
</tr>
<tr>
<td>SQLvariant: @AdamMachanic &#8230; I know what you&#8217;re going to say: File Group level backup.</td>
<td>Thu, 11 Feb 2010 02:07:51</td>
<td>http://twitter.com/SQLvariant/statuses/8940859327</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant Wrong, I wouldn&#8217;t say that. Because I barely ever deal with backups and it wouldn&#8217;t occur to me <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </td>
<td>Thu, 11 Feb 2010 02:08:35</td>
<td>http://twitter.com/AdamMachanic/statuses/8940891847</td>
</tr>
<tr>
<td>SQLvariant: @AdamMachanic more like noone does same type of range searches after 3 months.If they&#8217;re looking for an 18 month old record they know the id</td>
<td>Thu, 11 Feb 2010 02:10:17</td>
<td>http://twitter.com/SQLvariant/statuses/8940966189</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant Hmm, that might change things&#8211;you wouldn&#8217;t necessarily have to bear the query maintenance nightmare. What if, instead of 1/2</td>
<td>Thu, 11 Feb 2010 02:13:55</td>
<td>http://twitter.com/AdamMachanic/statuses/8941122014</td>
</tr>
<tr>
<td>SQLvariant: @AdamMachanic lets put it this way, I don&#8217;t care if &#8216;old-record&#8217; queries take 100x longer because they are out-numbered 12,000:1 by &#8216;new&#8217;</td>
<td>Thu, 11 Feb 2010 02:14:31</td>
<td>http://twitter.com/SQLvariant/statuses/8941147347</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant filtering on the date col, you create a BIT col, IsInLast90Days, and update it nightly? Then filter your index on that? And 2/3</td>
<td>Thu, 11 Feb 2010 02:14:34</td>
<td>http://twitter.com/AdamMachanic/statuses/8941149460</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant use that column in the WHERE clause in all of the range queries 3/3</td>
<td>Thu, 11 Feb 2010 02:14:50</td>
<td>http://twitter.com/AdamMachanic/statuses/8941160597</td>
</tr>
<tr>
<td>SQLvariant: @AdamMachanic oh, so what I was thinking was filter on last 90 days, then INCLUDE like 6 additional columns. Can I do that?</td>
<td>Thu, 11 Feb 2010 02:15:50</td>
<td>http://twitter.com/SQLvariant/statuses/8941204408</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant Yes, you can have included columns in a filtered index</td>
<td>Thu, 11 Feb 2010 02:16:46</td>
<td>http://twitter.com/AdamMachanic/statuses/8941244702</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant the important thing is you can&#8217;t filter on &#8220;last 90 days&#8221; &#8212; you have to include an actual date. That&#8217;s why I suggested BIT col</td>
<td>Thu, 11 Feb 2010 02:18:32</td>
<td>http://twitter.com/AdamMachanic/statuses/8941317917</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant Then it becomes 100% data-driven and you don&#8217;t have to change any indexes or queries to keep it working</td>
<td>Thu, 11 Feb 2010 02:19:02</td>
<td>http://twitter.com/AdamMachanic/statuses/8941338868</td>
</tr>
<tr>
<td>SQLvariant: @AdamMachanic ok. Well doing the bit column would make the filtered indexes even smaller too. I like your solution .</td>
<td>Thu, 11 Feb 2010 02:19:22</td>
<td>http://twitter.com/SQLvariant/statuses/8941352821</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant I think I&#8217;ll do a blog post on this <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  &#8230; thanks for the interesting discussion</td>
<td>Thu, 11 Feb 2010 02:20:07</td>
<td>http://twitter.com/AdamMachanic/statuses/8941384877</td>
</tr>
<tr>
<td>SQLvariant: @AdamMachanic I would just have to do heavy re-indexing on the weekends right? Oh no wait, I don&#8217;t!! because they&#8217;re on SSD drives <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /> </td>
<td>Thu, 11 Feb 2010 02:21:33</td>
<td>http://twitter.com/SQLvariant/statuses/8941449444</td>
</tr>
<tr>
<td>SQLvariant: @AdamMachanic Awesome. I think we may have solved more problems than we currently realize. please remember to mention me <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </td>
<td>Thu, 11 Feb 2010 02:25:00</td>
<td>http://twitter.com/SQLvariant/statuses/8941594839</td>
</tr>
<tr>
<td>SQLvariant: @AdamMachanic Hey maybe we could do this again next week and you could help me solve some of my XML dilemmas <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /> </td>
<td>Thu, 11 Feb 2010 02:42:36</td>
<td>http://twitter.com/SQLvariant/statuses/8942342844</td>
</tr>
<tr>
<td>AdamMachanic: @SQLvariant Sure thing! XML is something I love to hate&#8230;</td>
<td>Thu, 11 Feb 2010 03:12:23</td>
<td>http://twitter.com/AdamMachanic/statuses/8943583606</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://sqlvariant.com/wordpress/index.php/2010/02/filtered-indexes-the-conversation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://bit.ly/c7sHa8" length="77702636" type="video/x-ms-wmv" />
<enclosure url="http://bit.ly/c7sHa8" length="77702636" type="video/x-ms-wmv" />
<enclosure url="http://bit.ly/c7sHa8" length="77702636" type="video/x-ms-wmv" />
<enclosure url="http://bit.ly/c7sHa8" length="77702636" type="video/x-ms-wmv" />
<enclosure url="http://bit.ly/c7sHa8" length="77702636" type="video/x-ms-wmv" />
		</item>
		<item>
		<title>Lunch-n-Learn #01: SQL Server 2005 Features</title>
		<link>http://sqlvariant.com/wordpress/index.php/2010/01/lunch-n-learn-01-sql-server-2005-features/</link>
		<comments>http://sqlvariant.com/wordpress/index.php/2010/01/lunch-n-learn-01-sql-server-2005-features/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 15:36:48 +0000</pubDate>
		<dc:creator>Aaron Nelson</dc:creator>
				<category><![CDATA[Productivity]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SSMS]]></category>

		<guid isPermaLink="false">http://sqlvariant.com/wordpress/index.php/2010/01/lunch-n-learn-01-sql-server-2005-features/</guid>
		<description><![CDATA[Yesterday I did a quick Lunch-n-Learn here at my company on a few SQL Server 2005 features and this post is just a follow-up to remind everyone what we saw and where you can find those features.  I will try to still make this useful for those of you who didn’t attend. 0:  To make any of these code examples work please download and install the Sample Databases for SQL Server.  (Don’t worry, they’re pretty small.) The first thing that you folks saw was the intelli-sense where as I was typing the name of a table and SQL Server Management Studio (SSMS) was finishing the table name for me.  That was the only SQL Server 2008 exclusive feature that you saw in the entire session.  You can only see this if you have the SSMS 2008 client pointed to a SQL 2008 db. I showed you guys how to find out the name of every table and column of the db that you are in using the system views: SELECT * FROM INFORMATION_SCHEMA.TABLES SELECT * FROM INFORMATION_SCHEMA.COLUMNS Ticks!  How did this apostrophe get into our db?  And how do we get it out? SELECT  [Comments] ,[ProductReviewID] ,[ProductID] ,[ReviewerName] ,[ReviewDate] ,[EmailAddress] ,[Rating] ,[ModifiedDate]   FROM [AdventureWorks].[Production].[ProductReview] Well you just use 2 ticks to insert a single tick.  Said again, you use “’’” to insert “’” into SQL. Here’s an example from the AdventureWorks database: SET IDENTITY_INSERT [Production].[ProductReview] ON INSERT [Production].[ProductReview] ([ProductReviewID], [ProductID], [ReviewerName], [ReviewDate], [EmailAddress], [Rating], [Comments], [ModifiedDate]) VALUES (6, 709, &#8216;John Smith&#8217;, CAST(0&#215;0000941800000000 AS DateTime), &#8220;&#62;&#8216;john@fourthcoffee.com&#8217;, 5 , &#8216;I can&#8221;t believe I&#8221;m singing the praises of a pair of socks, but I just came back from a grueling 3-day ride and these socks really helped make the trip a blast. They&#8221;re lightweight yet really cushioned my feet all day. The reinforced toe is nearly bullet-proof and I didn&#8221;t experience any problems with rubbing or blisters like I have with other brands. I know it sounds silly, but it&#8221;s always the little stuff (like comfortable feet) that makes or breaks a long trip. I won&#8221;t go on another trip without them!&#8217;, CAST(0&#215;0000941800000000 AS DateTime)) SET IDENTITY_INSERT [Production].[ProductReview] OFF And we can get it out like this: UPDATE [Production].[ProductReview]    SET Comments = REPLACE(Comments, &#8221;&#8221;, &#8221;)  WHERE ProductReviewID = 6 To make your keyboard as useful as mine what you do is open up SSMS click on Tool &#62; Options &#62; Environment &#62; Keyboard &#62;and add the commands that you would like the corresponding shortcut key to execute. What Exactly is XACT_ABORT?  When XACT_ABORT is ON SQL Server will stop and roll back the transaction as soon as it hits an error; it won’t continue processing all the way to the end.  “When SET XACT_ABORT is OFF, in some cases only the Transact-SQL statement that raised the error is rolled back and the transaction continues processing.” Use this script to see it work for yourself. The next feature that I showed you was how you can create an Identity Column for the data you are  selecting without having to insert the data into a table by using the ROW_NUMBER() function.  I mentioned several other features along with that one and I will demo those features in our next Lunch-n-Learn.  In the meantime here’s a script that will show you it do 4 different row numbers on 4 different fields all at the same time. /* SQL Purists: please don’t freak out at this script, I’m just showing functionality*/ SELECT TOP 500 *              ROW_NUMBER() OVER (ORDER BY AvgCPUTime DESC) AS 'AVG Time Rank'        ,     ROW_NUMBER() OVER (ORDER BY total_cpu_time DESC) AS 'Total CPU Rank'        ,     ROW_NUMBER() OVER (ORDER BY total_duration_time DESC) AS 'Total Duration Rank'        ,     ROW_NUMBER() OVER (ORDER BY total_execution_count DESC) AS 'Total Executions Rank'        , a.TEXT AS 'StatementText'        , a.total_cpu_time        , a.total_execution_count        , a.total_duration_time        , a.AvgCPUTime        , a.number_of_statements        , a.plan_handle        , SUBSTRING(a.TEXT, 1, 100) AS 'hundy', a.name   FROM (        SELECT              sql_text.TEXT,            SUM(qs.total_worker_time) AS total_cpu_time,�            SUM(qs.total_elapsed_time) AS total_duration_time,�            SUM(qs.execution_count) AS total_execution_count,            SUM(qs.total_worker_time) / SUM(qs.execution_count) AS AvgCPUTime,            COUNT(*) AS  number_of_statements,�            qs.plan_handle , db.name        FROM�            sys.dm_exec_query_stats qs            CROSS apply sys.dm_exec_sql_text(sql_handle) AS sql_text        LEFT OUTER JOIN sys.databases db          ON sql_text.dbid = db.database_id        --WHERE dbid = 10        GROUP BY sql_text.TEXT,        qs.plan_handle , db.name )a ORDER BY AvgCPUTime DESC Comparing which way is better.  To compare how long and how much data was needed to satisfy two different queries you can just click on the Include Client Statistics button before you run the first query and it will start capturing the statistics for you: And finally the built-in reports.  To run any of them just Right-Click any database in SSMS Object Explorer and navigate to the report that you want: That pretty much wraps it up for what we covered yesterday.  I will put some examples together for the Common Table Expressions (CTE), RANK, DENSE_RANK, and NTILE fuctions that I mentioned yesterday so that we can go over them at the next one.  Next Tuesday work good for you?  If you would like anything else covered you can just email me or comment here.]]></description>
			<content:encoded><![CDATA[<p>Yesterday I did a quick Lunch-n-Learn here at my company on a few SQL Server <strong>2005</strong> features and this post is just a follow-up to remind everyone what we saw and where you can find those features.  I will try to still make this useful for those of you who didn’t attend.</p>
<p>0:  To make any of these code examples work please download and install the <a href="http://msftdbprodsamples.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=37109" target="_blank">Sample Databases for SQL Server</a>.  (Don’t worry, they’re pretty small.)</p>
<ol>
<li>The first thing that you folks saw was the intelli-sense where as I was typing the name of a table and SQL Server Management Studio (SSMS) was finishing the table name for me.  That was the <span style="text-decoration: underline;">only</span> SQL Server 2008 exclusive feature that you saw in the entire session.  You can only see this if you have the SSMS 2008 client pointed to a SQL 2008 db.</li>
<li>I showed you guys how to find out the name of every table and column of the db that you are in using the system views:<br />
<span style="color: #0000ff;">SELECT</span> *<br />
<span style="color: #0000ff;">FROM</span> <span style="color: #008000;">INFORMATION_SCHEMA</span>.<span style="color: #008000;">TABLES </span></li>
<p><span style="color: #0000ff;">SELECT</span> *<br />
<span style="color: #0000ff;">FROM</span> <span style="color: #008000;">INFORMATION_SCHEMA</span>.<span style="color: #008000;">COLUMNS</span></p>
<li><strong>Ticks!</strong>  How did this apostrophe get into our db?  And how do we get it out?<br />
<span style="color: #0000ff;">SELECT</span>  [Comments] ,[ProductReviewID] ,[ProductID] ,[ReviewerName] ,[ReviewDate] ,[EmailAddress] ,[Rating] ,[ModifiedDate]<br />
  <span style="color: #0000ff;">FROM</span> [AdventureWorks].[Production].[ProductReview]</li>
<p>Well you just use 2 ticks to insert a single tick.  Said again, you use “<span style="color: #ff0000;">’’</span>” to insert “<span style="color: #ff0000;">’</span>” into SQL. Here’s an example from the AdventureWorks database:<br />
<span style="color: #0000ff;">SET IDENTITY_INSERT</span> [Production].[ProductReview] <span style="color: #0000ff;">ON</span><br />
INSERT [Production].[ProductReview] ([ProductReviewID], [ProductID], [ReviewerName], [ReviewDate], [EmailAddress], [Rating], [Comments], [ModifiedDate])<br />
<span style="color: #0000ff;">VALUES</span><br />
(6, 709, <span style="color: #ff0000;">&#8216;John Smith&#8217;</span>, <span style="color: #ff00ff;">CAST</span>(0&#215;0000941800000000 <span style="color: #0000ff;">AS DateTime</span>), &#8220;&gt;<span style="color: #ff0000;">&#8216;john@fourthcoffee.com&#8217;</span>, 5<br />
, <span style="color: #ff0000;">&#8216;I can&#8221;t believe I&#8221;m singing the praises of a pair of socks, but I just came back from a grueling<br />
3-day ride and these socks really helped make the trip a blast. They&#8221;re lightweight yet really cushioned my feet all day.<br />
The reinforced toe is nearly bullet-proof and I didn&#8221;t experience any problems with rubbing or blisters like I have with<br />
other brands. I know it sounds silly, but it&#8221;s always the little stuff (like comfortable feet) that makes or breaks a long trip.<br />
I won&#8221;t go on another trip without them!&#8217;</span>, <span style="color: #ff00ff;">CAST</span>(0&#215;0000941800000000 <span style="color: #0000ff;">AS DateTime</span>))<br />
<span style="color: #0000ff;">SET IDENTITY_INSERT</span> [Production].[ProductReview] <span style="color: #0000ff;">OFF</span></p>
<p>And we can get it out like this:<br />
<span style="color: #0000ff;">UPDATE</span> [Production].[ProductReview]<br />
   <span style="color: #0000ff;">SET</span> Comments = <span style="color: #ff00ff;">REPLACE</span>(Comments, <span style="color: #ff0000;">&#8221;&#8221;</span>, <span style="color: #ff0000;">&#8221;</span>)<br />
 <span style="color: #0000ff;">WHERE</span> ProductReviewID = 6</p>
<li>To make your <strong>keyboard</strong> as useful as mine what you do is open up SSMS click on Tool &gt; Options &gt; Environment &gt; Keyboard &gt;and add the commands that you would like the corresponding shortcut key to execute.<br />
<a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/01/image.png"><img style="display: inline; border: 0px;" title="image" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/01/image_thumb.png" border="0" alt="image" width="534" height="313" /></a></li>
<li>What Exactly is <strong>XACT_ABORT</strong>?  When XACT_ABORT is ON SQL Server will stop and roll back the transaction as soon as it hits an error; it won’t continue processing all the way to the end.  “When SET XACT_ABORT is OFF, in some cases only the Transact-SQL statement that raised the error is rolled back and the transaction continues processing.”<br />
Use this <a href="http://SQLvariant.com/BlogSupport/XACT_ABORT_Example.sql" target="_blank">script</a> to see it work for yourself.</li>
<li>The next feature that I showed you was how you can create an Identity Column for the data you are  selecting without having to insert the data into a table by using the <span style="color: #ff00ff;">ROW_NUMBER</span>() function.  I mentioned several other features along with that one and I will demo those features in our next Lunch-n-Learn.  In the meantime here’s a script that will show you it do 4 different row numbers on 4 different fields all at the same time.<br />
<span style="color: #008000;">/* SQL Purists: please don’t freak out at this script, I’m just showing functionality*/</span><code style="font-size: 12px;"><span style="color: black;"><br />
</span><span style="color: blue;">SELECT TOP </span><span style="color: black;">500 *<br />
            <span style="color: #ff00ff;"> ROW_NUMBER</span></span><span style="color: gray;">() </span><span style="color: blue;">OVER </span><span style="color: gray;">(</span><span style="color: blue;">ORDER BY </span><span style="color: black;">AvgCPUTime </span><span style="color: blue;">DESC</span><span style="color: gray;">) </span><span style="color: blue;">AS </span><span style="color: red;">'AVG Time Rank'<br />
       </span><span style="color: gray;">,     </span><span style="color: #ff00ff;">ROW_NUMBER</span><span style="color: gray;">() </span><span style="color: blue;">OVER </span><span style="color: gray;">(</span><span style="color: blue;">ORDER BY </span><span style="color: black;">total_cpu_time </span><span style="color: blue;">DESC</span><span style="color: gray;">) </span><span style="color: blue;">AS </span><span style="color: red;">'Total CPU Rank'<br />
       </span><span style="color: gray;">,     </span><span style="color: #ff00ff;">ROW_NUMBER</span><span style="color: gray;">() </span><span style="color: blue;">OVER </span><span style="color: gray;">(</span><span style="color: blue;">ORDER BY </span><span style="color: black;">total_duration_time </span><span style="color: blue;">DESC</span><span style="color: gray;">) </span><span style="color: blue;">AS </span><span style="color: red;">'Total Duration Rank'<br />
       </span><span style="color: gray;">,     </span><span style="color: #ff00ff;">ROW_NUMBER</span><span style="color: gray;">() </span><span style="color: blue;">OVER </span><span style="color: gray;">(</span><span style="color: blue;">ORDER BY </span><span style="color: black;">total_execution_count </span><span style="color: blue;">DESC</span><span style="color: gray;">) </span><span style="color: blue;">AS </span><span style="color: red;">'Total Executions Rank'<br />
       </span><span style="color: gray;">, </span><span style="color: black;">a.</span><span style="color: blue;">TEXT AS </span><span style="color: red;">'StatementText'<br />
       </span><span style="color: gray;">, </span><span style="color: black;">a.total_cpu_time<br />
       </span><span style="color: gray;">, </span><span style="color: black;">a.total_execution_count<br />
       </span><span style="color: gray;">, </span><span style="color: black;">a.total_duration_time<br />
       </span><span style="color: gray;">, </span><span style="color: black;">a.AvgCPUTime<br />
       </span><span style="color: gray;">, </span><span style="color: black;">a.number_of_statements<br />
       </span><span style="color: gray;">, </span><span style="color: black;">a.plan_handle<br />
       </span><span style="color: gray;">, </span><span style="color: magenta;">SUBSTRING</span><span style="color: gray;">(</span><span style="color: black;">a.</span><span style="color: blue;">TEXT</span><span style="color: gray;">, </span><span style="color: black;">1</span><span style="color: gray;">, </span><span style="color: black;">100</span><span style="color: gray;">) </span><span style="color: blue;">AS </span><span style="color: red;">'hundy'</span><span style="color: gray;">, </span><span style="color: black;">a.name<br />
  </span><span style="color: blue;">FROM </span><span style="color: gray;">(<br />
       </span><span style="color: blue;">SELECT<br />
             </span><span style="color: black;">sql_text.</span><span style="color: blue;">TEXT</span><span style="color: gray;">,<br />
           </span><span style="color: magenta;">SUM</span><span style="color: gray;">(</span><span style="color: black;">qs.total_worker_time</span><span style="color: gray;">) </span><span style="color: blue;">AS </span><span style="color: black;">total_cpu_time</span><span style="color: gray;">,�<br />
           </span><span style="color: magenta;">SUM</span><span style="color: gray;">(</span><span style="color: black;">qs.total_elapsed_time</span><span style="color: gray;">) </span><span style="color: blue;">AS </span><span style="color: black;">total_duration_time</span><span style="color: gray;">,�<br />
           </span><span style="color: magenta;">SUM</span><span style="color: gray;">(</span><span style="color: black;">qs.execution_count</span><span style="color: gray;">) </span><span style="color: blue;">AS </span><span style="color: black;">total_execution_count</span><span style="color: gray;">,<br />
           </span><span style="color: magenta;">SUM</span><span style="color: gray;">(</span><span style="color: black;">qs.total_worker_time</span><span style="color: gray;">) / </span><span style="color: magenta;">SUM</span><span style="color: gray;">(</span><span style="color: black;">qs.execution_count</span><span style="color: gray;">) </span><span style="color: blue;">AS </span><span style="color: black;">AvgCPUTime</span><span style="color: gray;">,<br />
           </span><span style="color: magenta;">COUNT</span><span style="color: gray;">(*) </span><span style="color: blue;">AS  </span><span style="color: black;">number_of_statements</span><span style="color: gray;">,�<br />
           </span><span style="color: black;">qs.plan_handle </span><span style="color: gray;">, </span><span style="color: black;">db.name<br />
       </span><span style="color: blue;">FROM�<br />
           </span><span style="color: black;">sys.dm_exec_query_stats qs<br />
           </span><span style="color: gray;">CROSS </span><span style="color: black;">apply sys.dm_exec_sql_text</span><span style="color: gray;">(</span><span style="color: black;">sql_handle</span><span style="color: gray;">) </span><span style="color: blue;">AS </span><span style="color: black;">sql_text<br />
       </span><span style="color: magenta;">LEFT </span><span style="color: gray;">OUTER </span><span style="color: blue;">JOIN </span><span style="color: black;">sys.databases db<br />
         </span><span style="color: blue;">ON </span><span style="color: black;">sql_text.dbid </span><span style="color: blue;">= </span><span style="color: black;">db.database_id<br />
       </span><span style="color: green;">--WHERE dbid = 10<br />
       </span><span style="color: blue;">GROUP BY </span><span style="color: black;">sql_text.</span><span style="color: blue;">TEXT</span><span style="color: gray;">,<br />
       </span><span style="color: black;">qs.plan_handle </span><span style="color: gray;">, </span><span style="color: black;">db.name<br />
</span><span style="color: gray;">)</span><span style="color: black;">a<br />
</span><span style="color: blue;">ORDER BY </span><span style="color: black;">AvgCPUTime </span><span style="color: blue;">DESC</span></code></li>
<li><strong>Comparing</strong> which way is better.  To compare how long and how much data was needed to satisfy two different queries you can just click on the Include Client Statistics button before you run the first query and it will start capturing the statistics for you:<br />
<a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/01/image1.png"><img style="display: inline; border: 0px;" title="image" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/01/image_thumb1.png" border="0" alt="image" width="521" height="267" /></a></li>
<li>And finally the <strong>built-in reports</strong>.  To run any of them just Right-Click any database in SSMS Object Explorer and navigate to the report that you want:<br />
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="961" height="612" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://sqlvariant.com/wordpress/wp-content/uploads/2010/01/BuiltIn_Reports.jpg" /><embed type="application/x-shockwave-flash" width="961" height="612" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/01/BuiltIn_Reports.jpg"></embed></object></li>
</ol>
<p>That pretty much wraps it up for what we covered yesterday.  I will put some examples together for the Common Table Expressions (CTE), RANK, DENSE_RANK, and NTILE fuctions that I mentioned yesterday so that we can go over them at the next one.  Next Tuesday work good for you?  <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /><br />
If you would like anything else covered you can just email me or comment here.</p>
]]></content:encoded>
			<wfw:commentRss>http://sqlvariant.com/wordpress/index.php/2010/01/lunch-n-learn-01-sql-server-2005-features/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>T-SQL Tuesday #002 A Puzzling Situation: Max Server Memory</title>
		<link>http://sqlvariant.com/wordpress/index.php/2010/01/t-sql-tuesday-002-a-puzzling-situation-max-server-memory-2/</link>
		<comments>http://sqlvariant.com/wordpress/index.php/2010/01/t-sql-tuesday-002-a-puzzling-situation-max-server-memory-2/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 15:23:00 +0000</pubDate>
		<dc:creator>Aaron Nelson</dc:creator>
				<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Database Migration]]></category>
		<category><![CDATA[Server Configuration]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[T-SQL Tuesday]]></category>

		<guid isPermaLink="false">http://sqlvariant.com/wordpress/?p=293</guid>
		<description><![CDATA[Today&#8217;s post about changing your Max Server Memory setting is to answer the call from Adam Machanic about Puzzling Situations . A couple weeks before I headed out to the 2009 PASS Summit I encountered a puzzler of my own. One of our servers issued an alert that it had an extremely low Page Life Expectancy (PLE); like 16. All of the databases on this server had recently migrated from an older 32 bit server with 4 GB of RAM to thier current 64 bit server with 8 GB of RAM. As luck would have it, this was the source of my puzzling situation. When we migrated the dbs we inadvertantly transfered the memory configuration used in their old 32 bit server home. Who made this classic rookie error?? Yours truly. I was doing two server migrations at once and bobbled the checklists. I rectified the situation by increasing the RAM settings from 3 GB to 6 GB: sp_configure 'max server memory (MB)', '6144' RECONFIGURE Want to guess what happened when I ran the RECONFIGURE command? I watched as the perfmon counters immediately went down! Indicating that memory usage had dropped rather than increased. As it turns out in SQL Server 2005 (and in SQL Server 2008 as far as I know) when you run RECONFIGURE for anything you dump the procedure cache. So for example if you were to change the setting for ‘”Web Assistant Procedures” you would dump the procedure cache. If you were to change the setting for “fill factor (%)” you would dump the procedure cache. So beware before you change a configuration setting in your Production environment and run RECONFIGURE. So there&#8217;s my Puzzling Situations for T-SQL Tuesday #002]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s post about changing your Max Server Memory setting is to answer the call from Adam Machanic about <a href="http://sqlblog.com/blogs/adam_machanic/archive/2010/01/04/invitation-for-t-sql-tuesday-002-a-puzzling-situation.aspx">Puzzling Situations </a>.</p>
<p>A couple weeks before I headed out to the <a href="http://summit2009.sqlpass.org/">2009 PASS Summit </a>I encountered a puzzler of my own.  One of our servers issued an alert that it had an extremely low Page Life Expectancy (PLE); like 16.  All of the databases on this server had recently migrated from an older 32 bit server with 4 GB of RAM to thier current 64 bit server with 8 GB of RAM.  As luck would have it, this was the source of my puzzling situation. When we migrated the dbs we inadvertantly transfered the memory configuration used in their old 32 bit server home.  Who made this classic rookie error??  Yours truly.  I was doing two server migrations at once and bobbled the checklists.</p>
<p>I rectified the situation by increasing the RAM settings from 3 GB  to 6 GB:<code> </code></p>
<p><code><code><span style="color: #800000;">sp_configure</span> <span style="color: #ff0000;">'max server memory (MB)'</span><span style="color: #c0c0c0;">,</span> <span style="color: #ff0000;">'6144'</span><br />
<span style="color: #0000ff;">RECONFIGURE</span></code></code></p>
<p><a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/01/MaxRAMBefore1.jpg"><img title="MaxRAMBefore" style="display: inline; border: 0px;" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/01/MaxRAMBefore_thumb.jpg" border="0" alt="MaxRAMBefore" width="556" height="234" /></a></p>
<p>Want to guess what happened when I ran the RECONFIGURE command?</p>
<p>I watched as the perfmon counters immediately <span style="color: #ff0000;"><strong><span style="text-decoration: underline;">went down!</span> </strong><span style="color: #000000;">Indicating that memory usage had dropped rather than increased.</span></span></p>
<p><a href="http://sqlvariant.com/wordpress/wp-content/uploads/2010/01/MaxRAMAfter1.jpg"><img title="MaxRAMAfter" style="display: inline; border: 0px;" src="http://sqlvariant.com/wordpress/wp-content/uploads/2010/01/MaxRAMAfter_thumb.jpg" border="0" alt="MaxRAMAfter" width="559" height="243" /></a></p>
<p>As it turns out in SQL Server 2005 (and in SQL Server 2008 as far as I know) when you run RECONFIGURE for <span style="text-decoration: underline;">anything</span> you dump the procedure cache.  So for example if you were to change the setting for ‘”Web Assistant Procedures” you would dump the procedure cache.  If you were to change the setting for “fill factor (%)” you would dump the procedure cache.</p>
<p>So beware before you change a configuration setting in your Production environment and run <span style="color: #0000ff;">RECONFIGURE.</span></p>
<p>So there&#8217;s my Puzzling Situations for T-SQL Tuesday #002</p>
]]></content:encoded>
			<wfw:commentRss>http://sqlvariant.com/wordpress/index.php/2010/01/t-sql-tuesday-002-a-puzzling-situation-max-server-memory-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>T-SQL Tuesday Date, Time, tricks with the DateTime Data Type</title>
		<link>http://sqlvariant.com/wordpress/index.php/2009/12/t-sql-tuesday-date-time-tricks-with-the-datetime-data-type/</link>
		<comments>http://sqlvariant.com/wordpress/index.php/2009/12/t-sql-tuesday-date-time-tricks-with-the-datetime-data-type/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 00:43:22 +0000</pubDate>
		<dc:creator>Aaron Nelson</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[T-SQL Tuesday]]></category>

		<guid isPermaLink="false">http://sqlvariant.com/wordpress/?p=175</guid>
		<description><![CDATA[Adam Machanic told us all about a new craze sweeping the SQL Blogosphere Nation last week and that is T-SQL Tuesdays. Real quick, the way it works is that on Patch-Tuesday everyone who’s got something to say about the topic of the month releases a blog post about it and the “Host” of the topic recaps all of the various blog posts in a blog at their site. OK now onto the topic. Because I think there might be a few people bolgging about this today I will keep min short-and-sweet and go over 5 main points of the Old-School DateTime data type. Before I start I want to remind you that DBAs Data Professionals are a little different, a lot of us think in terms of Largest to Smallest unit when we think of DateTime; which makes it into the way that you think of a standard number. Right now it is “200912051505” or “2009-12-05 15:05” Selecting and aggregating using Styles all of the rows in a table can be a little problematic if you are selecting a date that looks something like this one “2009-12-05 15:05”. One of my favorite ways to get around this is with the CONVERT function and changing it to a VARCHAR and then using a style. Here’s what I usually do. Run this query in AdventureWorks and you’ll notice that it also pulls in time which might be something that we want to avoid: SELECT COUNT(*) AS '# of Orders' , OrderDate AS 'Order Date' FROM Sales.SalesOrderHeader GROUP BY OrderDate ORDER BY OrderDate # of Orders Order Date 32 2008-07-28 00:00:00.000 31 2008-07-29 00:00:00.000 23 2008-07-30 00:00:00.000 40 2008-07-31 00:00:00.000 So what I do is CONVERT it to VARCHAR and then add Style 112 to it SELECT COUNT(*) AS '# of Orders' , CONVERT(VARCHAR, OrderDate, 112) AS 'Order Date' FROM Sales.SalesOrderHeader GROUP BY CONVERT(VARCHAR, OrderDate, 112) ORDER BY CONVERT(VARCHAR, OrderDate, 112) # of Orders Order Date 32 20080728 31 20080729 23 20080730 40 20080731 Now this isn’t overly readable but it sorts great. Another problem with it is that it doesn’t paste into Excel real well. For pasting into Excel and having it quickly recognize it as a DateTime field I use Style 110 but there’s a catch. Style 110 pastes into Excel fine but it doesn’t sort properly so I end up having to keep my Style 112 column so that I can sort on it. SELECT COUNT(*) AS '# of Orders' , CONVERT(VARCHAR, OrderDate, 110) AS 'Order Date' , CONVERT(VARCHAR, OrderDate, 112) AS 'Order Sort' FROM Sales.SalesOrderHeader GROUP BY CONVERT(VARCHAR, OrderDate, 110) , CONVERT(VARCHAR, OrderDate, 112) ORDER BY CONVERT(VARCHAR, OrderDate, 112) # of Orders Order Date 32 7/28/2008 31 7/29/2008 23 7/30/2008 40 7/31/2008 Selecting just the time with Style 108 is another trick I have used in the past. As a quick and easy way to extract just the time out of a DateTime field is to CONVERT it to VARCHAR making sure to specify a length of 5. (Now if you also want the seconds you need to make the length 8.) SELECT GETDATE() AS 'GetDate', CONVERT(VARCHAR(5) , GETDATE(), 108) AS 'GetTime' GetDate GetTime 2009-12-05 17:10:54.430 17:10 And now for my final trick Selecting the date of the Sunday of the Week (or any recurring day of the week) Sometimes – especially in Business Intelligence – you want to group data by week but you don’t want to use DATEPART (WK, OrderDate) because that produces a number and you might want something more like an actual date. In this case what I typically do is just use this: DATEADD(DAY, 1-DATEPART(WEEKDAY, OrderDate), OrderDate) (Now you can pick the Saturday of that week just as easily by swapping out that 1 for a 7.) SELECT COUNT(*) AS '# of Orders' , DATEPART (WK, OrderDate) , DATEADD(DAY, 1-DATEPART(WEEKDAY, OrderDate), OrderDate) AS 'Sunday of the Week' , DATEPART(WEEKDAY, OrderDate) AS 'Day# of Week' , CONVERT(VARCHAR, OrderDate, 112) AS 'Order Date' FROM Sales.SalesOrderHeader GROUP BY DATEPART (WK, OrderDate) , CONVERT(VARCHAR, OrderDate, 112) , DATEADD(DAY, 1-DATEPART(WEEKDAY, OrderDate), OrderDate) , DATEPART(WEEKDAY, OrderDate) ORDER BY CONVERT(VARCHAR, OrderDate, 112) # of Orders Sunday of the Week Day# of Week Order Date 24 2008-07-20 00:00:00.000 6 20080725 32 2008-07-20 00:00:00.000 7 20080726 29 2008-07-27 00:00:00.000 1 20080727 32 2008-07-27 00:00:00.000 2 20080728 31 2008-07-27 00:00:00.000 3 20080729 23 2008-07-27 00:00:00.000 4 20080730 40 2008-07-27 00:00:00.000 5 20080731 You can check out the rest of the blogs for this T-SQL Tuesday topic right here: http://sqlblog.com/blogs/adam_machanic/archive/2009/12/09/t-sql-tuesday-001-the-roundup.aspx or do a search on Twitter and look for the hash #TSQL2sDay. I hope this helps a few people out, as always if you have any questions please comment. TSQL2sDay]]></description>
			<content:encoded><![CDATA[<p>Adam Machanic told us all about a new craze sweeping the SQL Blogosphere Nation last week and that is <a href="http://sqlblog.com/blogs/adam_machanic/archive/2009/11/30/invitation-to-participate-in-t-sql-tuesday-001-date-time-tricks.aspx">T-SQL Tuesdays</a>.  Real quick, the way it works is that on Patch-Tuesday everyone who’s got something to say about the topic of the month releases a blog post about it and the “Host” of the topic recaps all of the various blog posts in a blog at their site.  OK now onto the topic.</p>
<p>Because I think there might be a few people bolgging about this today I will keep min short-and-sweet and go over 5 main points of the Old-School DateTime data type.</p>
<p>Before I start I want to remind you that <span style="text-decoration: line-through;">DBAs</span><strong> <a href="http://blogs.msdn.com/buckwoody/archive/2009/10/29/don-t-be-a-dba-be-a-data-professional.aspx">Data Professionals</a> </strong>are a little different, a lot of us think in terms of Largest to Smallest unit when we think of DateTime; which makes it into the way that you think of a standard number.  Right now it is “200912051505” or “2009-12-05 15:05”</p>
<p><strong><span style="color: #3366ff;">Selecting and aggregating using Styles</span></strong> all of the rows in a table can be a little problematic if you are selecting a date that looks something like this one “2009-12-05 15:05”.  One of my favorite ways to get around this is with the CONVERT function and changing it to a VARCHAR and then using a style.  Here’s what I usually do.</p>
<p>Run this query in AdventureWorks and you’ll notice that it also pulls in time which might be something that we want to avoid:</p>
<pre><span style="color: #0000ff;">SELECT</span> <span style="color: #ff00ff;">COUNT</span>(*) <span style="color: #0000ff;">AS</span> <span style="color: #ff0000;">'# of Orders'
</span> , OrderDate <span style="color: #0000ff;">AS</span> <span style="color: #ff0000;">'Order Date'</span>
  <span style="color: #0000ff;">FROM</span> Sales.SalesOrderHeader
 <span style="color: #0000ff;">GROUP</span> <span style="color: #0000ff;">BY </span>OrderDate
 <span style="color: #0000ff;">ORDER</span> <span style="color: #0000ff;">BY </span>OrderDate</pre>
<table border="0" cellspacing="0" cellpadding="0" width="261">
<colgroup span="1">
<col width="92" span="1"></col>
<col width="169" span="1"></col>
</colgroup>
<tbody>
<tr height="21">
<td width="92" height="21"># of Orders</td>
<td width="169">Order Date</td>
</tr>
<tr height="21">
<td height="21" align="right">32</td>
<td>2008-07-28 00:00:00.000</td>
</tr>
<tr height="20">
<td height="20" align="right">31</td>
<td>2008-07-29 00:00:00.000</td>
</tr>
<tr height="20">
<td height="20" align="right">23</td>
<td>2008-07-30 00:00:00.000</td>
</tr>
<tr height="20">
<td height="20" align="right">40</td>
<td>2008-07-31 00:00:00.000</td>
</tr>
</tbody>
</table>
<p>So what I do is CONVERT it to VARCHAR and then add Style 112 to it</p>
<pre><span style="color: #0000ff;">SELECT </span><span style="color: #ff00ff;">COUNT</span>(*) <span style="color: #0000ff;">AS</span> <span style="color: #ff0000;">'# of Orders'</span>
 , <span style="color: #ff00ff;">CONVERT</span>(<span style="color: #0000ff;">VARCHAR</span>, OrderDate, 112) <span style="color: #0000ff;">AS</span> <span style="color: #ff0000;">'Order Date'</span>
  <span style="color: #0000ff;">FROM</span> Sales.SalesOrderHeader
 <span style="color: #0000ff;">GROUP BY</span> <span style="color: #ff00ff;">CONVERT</span>(<span style="color: #0000ff;">VARCHAR</span>, OrderDate, 112)
 <span style="color: #0000ff;">ORDER BY</span> <span style="color: #ff00ff;">CONVERT</span>(<span style="color: #0000ff;">VARCHAR</span>, OrderDate, 112)</pre>
<table border="0" cellspacing="0" cellpadding="0" width="261">
<colgroup span="1">
<col width="92" span="1"></col>
<col width="169" span="1"></col>
</colgroup>
<tbody>
<tr height="21">
<td width="92" height="21"># of Orders</td>
<td width="169">Order Date</td>
</tr>
<tr height="20">
<td height="20" align="right">32</td>
<td>20080728</td>
</tr>
<tr height="20">
<td height="20" align="right">31</td>
<td>20080729</td>
</tr>
<tr height="20">
<td height="20" align="right">23</td>
<td>20080730</td>
</tr>
<tr height="20">
<td height="20" align="right">40</td>
<td>20080731</td>
</tr>
</tbody>
</table>
<p>Now this isn’t overly readable but it sorts great.    Another problem with it is that it doesn’t paste into Excel real well.  For pasting into Excel and having it quickly recognize it as a DateTime field I use Style 110 but there’s a catch.  Style 110 pastes into Excel fine but it doesn’t sort properly so I end up having to keep my Style 112 column so that I can sort on it.</p>
<pre><span style="color: #0000ff;">SELECT </span><span style="color: #ff00ff;">COUNT</span>(*) <span style="color: #0000ff;">AS</span> '# of Orders'
  , <span style="color: #ff00ff;">CONVERT</span>(<span style="color: #0000ff;">VARCHAR</span>, OrderDate, 110) <span style="color: #0000ff;">AS</span> 'Order Date'
  , <span style="color: #ff00ff;">CONVERT</span>(VARCHAR, OrderDate, 112) <span style="color: #0000ff;">AS</span> 'Order Sort'
  <span style="color: #0000ff;">FROM</span> Sales.SalesOrderHeader
 <span style="color: #0000ff;">GROUP</span> <span style="color: #0000ff;">BY</span> <span style="color: #ff00ff;">CONVERT</span>(<span style="color: #0000ff;">VARCHAR</span>, OrderDate, 110)
  , <span style="color: #ff00ff;">CONVERT</span>(<span style="color: #0000ff;">VARCHAR</span>, OrderDate, 112)
 <span style="color: #0000ff;">ORDER BY</span> <span style="color: #ff00ff;">CONVERT</span>(<span style="color: #0000ff;">VARCHAR</span>, OrderDate, 112)</pre>
<table border="0" cellspacing="0" cellpadding="0" width="261">
<colgroup span="1">
<col width="92" span="1"></col>
<col width="169" span="1"></col>
</colgroup>
<tbody>
<tr height="21">
<td width="92" height="21"># of Orders</td>
<td width="169">Order Date</td>
</tr>
<tr height="20">
<td height="20" align="right">32</td>
<td>7/28/2008</td>
</tr>
<tr height="20">
<td height="20" align="right">31</td>
<td>7/29/2008</td>
</tr>
<tr height="20">
<td height="20" align="right">23</td>
<td>7/30/2008</td>
</tr>
<tr height="20">
<td height="20" align="right">40</td>
<td>7/31/2008</td>
</tr>
</tbody>
</table>
<p><strong>Selecting just the time </strong>with Style 108 is another trick I have used in the past.  As a quick and easy way to extract just the time out of a DateTime field is to CONVERT it to VARCHAR making sure to specify a length of 5.  (Now if you also want the seconds you need to make the length 8.)</p>
<pre><span style="color: #0000ff;">SELECT</span> <span style="color: #ff00ff;">GETDATE</span>() <span style="color: #0000ff;">AS</span> 'GetDate', <span style="color: #ff00ff;">CONVERT</span>(VARCHAR(5)
 , <span style="color: #ff00ff;">GETDATE</span>(), 108) <span style="color: #0000ff;">AS</span> 'GetTime'</pre>
<table border="0" cellspacing="0" cellpadding="0" width="243">
<colgroup span="1">
<col width="172" span="1"></col>
<col width="71" span="1"></col>
</colgroup>
<tbody>
<tr height="21">
<td width="172" height="21">GetDate</td>
<td width="71">GetTime</td>
</tr>
<tr height="20">
<td height="20">2009-12-05 17:10:54.430</td>
<td align="right">17:10</td>
</tr>
</tbody>
</table>
<p>And now for my final trick<br />
<strong>Selecting the date of the Sunday of the Week </strong>(or any recurring day of the week)</p>
<p>Sometimes – especially in Business Intelligence – you want to group data by week but you don’t want to use DATEPART (WK, OrderDate) because that produces a number and you might want something more like an actual date.  In this case what I typically do is just use this: DATEADD(DAY, 1-DATEPART(WEEKDAY, OrderDate), OrderDate)<br />
(Now you can pick the Saturday of that week just as easily by swapping out that 1 for a 7.)</p>
<pre><span style="color: #0000ff;">SELECT</span> <span style="color: #ff00ff;">COUNT</span>(*) <span style="color: #0000ff;">AS</span> '# of Orders'
 , <span style="color: #ff00ff;">DATEPART</span> (WK, OrderDate)
 , <span style="color: #ff00ff;">DATEADD</span>(<span style="color: #ff00ff;">DAY</span>, 1-<span style="color: #ff00ff;">DATEPART</span>(WEEKDAY, OrderDate), OrderDate) <span style="color: #0000ff;">AS</span> 'Sunday of the Week'
 , <span style="color: #ff00ff;">DATEPART</span>(WEEKDAY, OrderDate) <span style="color: #0000ff;">AS </span>'Day# of Week'
 , <span style="color: #ff00ff;">CONVERT</span>(<span style="color: #0000ff;">VARCHAR</span>, OrderDate, 112) <span style="color: #0000ff;">AS</span> 'Order Date'
  <span style="color: #0000ff;">FROM</span> Sales.SalesOrderHeader
 <span style="color: #0000ff;">GROUP BY</span> <span style="color: #ff00ff;">DATEPART</span> (WK, OrderDate)
 , <span style="color: #ff00ff;">CONVERT</span>(<span style="color: #0000ff;">VARCHAR</span>, OrderDate, 112)
 , <span style="color: #ff00ff;">DATEADD</span>(<span style="color: #ff00ff;">DAY</span>, 1-<span style="color: #ff00ff;">DATEPART</span>(WEEKDAY, OrderDate), OrderDate)
 , <span style="color: #ff00ff;">DATEPART</span>(WEEKDAY, OrderDate)
 <span style="color: #0000ff;">ORDER</span> <span style="color: #0000ff;">BY</span> <span style="color: #ff00ff;">CONVERT</span>(<span style="color: #0000ff;">VARCHAR</span>, OrderDate, 112)</pre>
<table border="0" cellspacing="0" cellpadding="0" width="420">
<colgroup span="1">
<col width="82" span="1"></col>
<col width="154" span="1"></col>
<col width="101" span="1"></col>
<col width="83" span="1"></col>
</colgroup>
<tbody>
<tr height="21">
<td width="82" height="21"># of Orders</td>
<td width="154">Sunday of the Week</td>
<td width="101">Day# of Week</td>
<td width="83">Order Date</td>
</tr>
<tr height="20">
<td height="20" align="right">24</td>
<td>2008-07-20 00:00:00.000</td>
<td align="right">6</td>
<td align="right">20080725</td>
</tr>
<tr height="20">
<td height="20" align="right">32</td>
<td>2008-07-20 00:00:00.000</td>
<td align="right">7</td>
<td align="right">20080726</td>
</tr>
<tr height="20">
<td height="20" align="right">29</td>
<td>2008-07-27 00:00:00.000</td>
<td align="right">1</td>
<td align="right">20080727</td>
</tr>
<tr height="20">
<td height="20" align="right">32</td>
<td>2008-07-27 00:00:00.000</td>
<td align="right">2</td>
<td align="right">20080728</td>
</tr>
<tr height="20">
<td height="20" align="right">31</td>
<td>2008-07-27 00:00:00.000</td>
<td align="right">3</td>
<td align="right">20080729</td>
</tr>
<tr height="21">
<td height="21" align="right">23</td>
<td>2008-07-27 00:00:00.000</td>
<td align="right">4</td>
<td align="right">20080730</td>
</tr>
<tr height="20">
<td height="20" align="right">40</td>
<td>2008-07-27 00:00:00.000</td>
<td align="right">5</td>
<td align="right">20080731</td>
</tr>
</tbody>
</table>
<p>You can check out the rest of the blogs for this T-SQL Tuesday topic right here:  <a href="http://sqlblog.com/blogs/adam_machanic/archive/2009/12/09/t-sql-tuesday-001-the-roundup.aspx">http://sqlblog.com/blogs/adam_machanic/archive/2009/12/09/t-sql-tuesday-001-the-roundup.aspx</a> or do a search on Twitter and look for the hash #<span style="color: #0000ff;">TSQL2sDay</span>.<br />
I hope this helps a few people out, as always if you have any questions please comment.<br />
<span style="color: #ffffff;">TSQL2sDay</span></p>
]]></content:encoded>
			<wfw:commentRss>http://sqlvariant.com/wordpress/index.php/2009/12/t-sql-tuesday-date-time-tricks-with-the-datetime-data-type/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using PowerShell to Archive Twitter Feeds&#8211;Preserving the wisdom of Paul Randal</title>
		<link>http://sqlvariant.com/wordpress/index.php/2009/11/using-powershell-to-archive-twitter-feeds-preserving-the-wisdom-of-paul-randal/</link>
		<comments>http://sqlvariant.com/wordpress/index.php/2009/11/using-powershell-to-archive-twitter-feeds-preserving-the-wisdom-of-paul-randal/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 16:03:01 +0000</pubDate>
		<dc:creator>Aaron Nelson</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Training Event]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://sqlvariant.com/wordpress/?p=152</guid>
		<description><![CDATA[If you didn’t make it out to the PASS Summit then you missed out on a lot of great content.  If you’re not on twitter and following some of SQL Server’s best and or rowdiest than you’re missing a lot.  And if you didn’t follow Paul Randal while he was tweeting from the session he and Kimberly L. Tripp presented then you missed a great refersher course on SQL fundamentals that are critical to your success in this field. The challenge of dealing with great content burried in tweets is figuring out how to capture that information in a way you can reference it later. I took a queue from of Bruce Payette’s book Windows PowerShell in Action and decided I&#8217;d try tackling this problem.  I started by visiting the PaulRandal twitter page. If you just wanted to download his last 20 tweets you could just use the RSS feed: http://twitter.com/statuses/user_timeline/36394357.rss .  How do you get the others? I got around the 20 tweet limitation by  favorite-ing Paul’s tweets starting at the beginning of the conference and then working my way toward the current date: Every time I selected 20 of Paul’s tweets as a favorite I just ran this PowerShell script and appended it to a file that I was storing them in.   ([xml] (new-object net.webclient).DownloadString(&#8220;http://twitter.com/favorites/76699854.rss&#8221;)).rss.channel.item &#124; format-table -autosize description, pubDate, link &#62;&#62; PaulRandal.txt After that I used SSIS to load them in a SQL db and help me clear out a few of the tweets that would be of little use without the other half of the conversation and what not.  I did learn a couple of interesting PowerShell quirks during this process.  The first is that your output is truncated based on your available screen size.  I began writing this script while running the PowerShell command in a 1280 x 1024 screen.  When my output was restricted I took a chance and tried running it on my laptop where the resolution is ste to 1920 x 1200. Running the download at a higher resolution was good enough to solve problem. (I haven’t yet found out why PowerShell kept trying to truncate in the first place. If you have ideas on this feel free to use the comments.)  The second was seeing the real differenece between the “&#62;&#62;”  and &#8220;&#62;&#8221; operators.  By using a double “&#62;&#62;” instead of a single “&#62;” I was able to append my output instead of completely replace it every time I ran my script.  Next time I’ll figure out how to pump it straight into a table so that I can skip the SSIS step. Finally here’s what I ended up with: Handle Tweet TweetDate TweetLink HashTags PaulRandal: And we&#8217;re on &#8211; pretty packed room here in our pre-con &#8211; just shy of 100. #sqlpass                 11/2/09 4:38 PM http://twitter.com/PaulRandal/statuses/5366919942 #sqlpass                 PaulRandal: #sqlpass Let&#8217;s make the hashtag for our indexing precon #ktprecon &#8211; I&#8217;ll watch both.                11/2/09 4:56 PM http://twitter.com/PaulRandal/statuses/5367318129 #sqlpass  #ktprecon  PaulRandal: Question from #sqlpass: Ever a use for heaps? A: Not really. E.g. incoming clickstream temp storage             11/2/09 4:58 PM http://twitter.com/PaulRandal/statuses/5367371468 #sqlpass:  PaulRandal: #sqlpass Either that or Kimberly&#8217;s jokes really *are* bad, and I&#8217;m just laughing because I have to (being married to her)       11/2/09 5:01 PM http://twitter.com/PaulRandal/statuses/5367439309 #sqlpass  PaulRandal: #ktprecon #sqlpass Q: why do SELECT COUNT(*) of a heap with fwded records generate extra IOs?              11/2/09 5:14 PM http://twitter.com/PaulRandal/statuses/5367732804 #ktprecon  #sqlpass  PaulRandal: #ktprecon #sqlpass A: because the Storage Engine will only process fwded records when it finds them from a fwding record       11/2/09 5:14 PM http://twitter.com/PaulRandal/statuses/5367744740 #ktprecon  #sqlpass  PaulRandal: @DBA_hole #ktprecon #sqlpass Yes (unless you specifically ask for a nonclustered primary key)              11/2/09 5:19 PM http://twitter.com/PaulRandal/statuses/5367850801 #ktprecon  #ktprecon  PaulRandal: @DBA_hole #ktprecon #sqlpass But not a drop/recreate. It&#8217;s a create of clustered index + drop of heap. Semantic, but important difference.   11/2/09 5:20 PM http://twitter.com/PaulRandal/statuses/5367869544 #ktprecon  #ktprecon  PaulRandal: #ktprecon #sqlpass Our wonderful attendees&#8230; http://pic.gd/b17455                     11/2/09 5:24 PM http://twitter.com/PaulRandal/statuses/5367969054 #ktprecon  #sqlpass  PaulRandal: #ktprecon #sqlpass Kimberly in mid-sentence&#8230; isn&#8217;t she cute? http://pic.gd/ba2662                11/2/09 5:26 PM http://twitter.com/PaulRandal/statuses/5368012672 #ktprecon  #sqlpass  PaulRandal: #ktprecon #sqlpass Ola Hallengren&#8217;s *wonderful* db maintenance script: http://bit.ly/3R5OUv               11/2/09 5:35 PM http://twitter.com/PaulRandal/statuses/5368219637 #ktprecon  #sqlpass  PaulRandal: @sqlinsaneo They&#8217;re not real seagulls &#8211; they&#8217;re MS-controlled robots #sqlpass                  11/2/09 5:37 PM http://twitter.com/PaulRandal/statuses/5368256080 #sqlpass                  PaulRandal: @buckwoody I&#8217;m trying to avoid looking at you &#8211; too embarrassed after what happened to us last night in that phone booth #sqlpass     11/2/09 5:42 PM http://twitter.com/PaulRandal/statuses/5368367982 #sqlpass     PaulRandal: #ktprecon #sqlpass Alternative to shrink: http://bit.ly/43PQI                      11/2/09 5:54 PM http://twitter.com/PaulRandal/statuses/5368638484 #ktprecon  #sqlpass  PaulRandal: @DBA_hole #ktprecon #sqlpass Depends on your I/O subsystem, filegroup layout, HA/DR strategy&#8230; may be more mgmt probs than gains     11/2/09 6:04 PM http://twitter.com/PaulRandal/statuses/5368853068 #ktprecon  #ktprecon  PaulRandal: #sqlpass Please refill the coffee in the speaker room (and have someone check regularly&#8230;) thanks!             11/2/09 6:38 PM http://twitter.com/PaulRandal/statuses/5369614171 #sqlpass  PaulRandal: @DonKirkham #sqlpass backup/restore does not reclaim space (or do anything else to the db). Only way to reclaim is some form of shrink.    11/2/09 6:41 PM http://twitter.com/PaulRandal/statuses/5369662274 #sqlpass  PaulRandal: @DonKirkham See http://bit.ly/43PQI for an alternative for you.                      11/2/09 6:51 PM http://twitter.com/PaulRandal/statuses/5369891151 NULL PaulRandal: @ktegels Because an existing filegroup has data files &#8211; a FS filegroup is a pointer to the root of the NTFS data container       11/2/09 6:52 PM http://twitter.com/PaulRandal/statuses/5369909736 NULL PaulRandal: #ktprecon #sqlpass How expensive are page splits in terms of transaction log? http://bit.ly/MqUgU             11/2/09 7:03 PM http://twitter.com/PaulRandal/statuses/5370157274 #ktprecon  #sqlpass  PaulRandal: #ktprecon #sqlpass Do page splits ever roll back? No: script to prove it: http://bit.ly/2IgMM3              11/2/09 7:04 PM http://twitter.com/PaulRandal/statuses/5370177946 #ktprecon  #sqlpass  PaulRandal: #ktprecon #sqlpass Demo scripts (and companion content for the internals book chapter) are at http://bit.ly/42zJ4c         11/2/09 7:10 PM http://twitter.com/PaulRandal/statuses/5370304102 #ktprecon  #sqlpass  PaulRandal: Audience perspective: RT @joewebb: Live from #ktprecon at #sqlpass.  http://twitpic.com/o13um              11/2/09 7:12 PM http://twitter.com/PaulRandal/statuses/5370346695 #ktprecon  #sqlpass PaulRandal: #ktprecon #sqlpass Kimberly dissing DBCC commands while I&#8217;m on stage next to her? Not a smart move!             11/2/09 7:17 PM http://twitter.com/PaulRandal/statuses/5370471853 #ktprecon  #sqlpass  PaulRandal: #ktprecon #sqlpass OH from Kimberly: &#8220;The key points are&#8230;. really just the key points.&#8221; Very astute observation there dear      11/2/09 7:45 PM http://twitter.com/PaulRandal/statuses/5371086548 #ktprecon  #sqlpass  PaulRandal: @ChiragRoy #ktprecon #sqlpass It depends Wait until she talks about indexing strategies this afternoon.           11/2/09 7:48 PM http://twitter.com/PaulRandal/statuses/5371143932 #ktprecon    PaulRandal: @AndyLeonard #sqlpass #ktprecon She&#8217;ll never see it &#8211; she doesn&#8217;t tweet much &#8211; I&#8217;m safe                11/2/09 7:49 PM http://twitter.com/PaulRandal/statuses/5371159601 #sqlpass  #ktprecon  PaulRandal: #sqlpass People.. the answer is always &#8220;it depends&#8221;. Apart from if the question is &#8216;should auto-shrink be turned on?&#8217;.        11/2/09 7:58 PM http://twitter.com/PaulRandal/statuses/5371365926 #sqlpass  PaulRandal: @datachick My other favorite answer is &#8220;12&#8243; and then watch the mystified expressions. #sqlpass              11/2/09 8:01 PM http://twitter.com/PaulRandal/statuses/5371421542 #sqlpass              PaulRandal: #sqlpass L U N C H    T I M E! #ktprecon We&#8217;ll be back to cover more incredible indexing info (and on-stage (verbal) spousal abuse!     11/2/09 8:03 PM http://twitter.com/PaulRandal/statuses/5371476694 #sqlpass  #ktprecon  PaulRandal: @DonKirkham Ah &#8211; no solution for that &#8211; maybe a 3rd-party backup/restore tool?                  11/2/09 8:52 PM http://twitter.com/PaulRandal/statuses/5372567849 NULL PaulRandal: #ktprecon #sqlpass Once more into the breach, dear friends, once more&#8230;.  back after lunch with the KT Indexing Show        11/2/09 9:05 PM http://twitter.com/PaulRandal/statuses/5372866600 #ktprecon  #sqlpass  PaulRandal: #ktprecon #sqlpass Don&#8217;t INCLUDE LOB columns in NC indexes. It creates a whole extra copy of the LOB data. Not good.        11/2/09 9:10 PM http://twitter.com/PaulRandal/statuses/5372989895 #ktprecon  #sqlpass  PaulRandal: #ktprecon #sqlpass And don&#8217;t put an index on every column. One of the worst things you can do.              11/2/09 9:13 PM http://twitter.com/PaulRandal/statuses/5373037864 #ktprecon  #sqlpass  PaulRandal: @SQLCraftsman Oh yeah. Confusing unto and into always gets me into unto-ward trouble.                11/2/09 9:16 PM http://twitter.com/PaulRandal/statuses/5373123933 NULL PaulRandal: #ktprecon #sqlpass What is a &#8216;seekable&#8217; index? An index with keys that can be used in a left-based subset to match a search argument.    11/2/09 9:23 PM http://twitter.com/PaulRandal/statuses/5373277154 #ktprecon  #sqlpass  PaulRandal: #ktprecon @sqlpass What order should the NC index key columns be in? It depends&#8230;                 11/2/09 9:24 PM http://twitter.com/PaulRandal/statuses/5373306090 #ktprecon  PaulRandal: #ktprecon #sqlpass So far Kimberly&#8217;s answered &#8220;It depends&#8221; 15 times&#8230;                    11/2/09 9:26 PM http://twitter.com/PaulRandal/statuses/5373359667 #ktprecon  #sqlpass  PaulRandal: #sqlpass Q I get asked: query perf dropping, what happened? If it slowly drops, fragmentation. If it drops off a cliff, stats. Commonly.   11/2/09 9:35 PM http://twitter.com/PaulRandal/statuses/5373562535 #sqlpass  PaulRandal: @ChiragRoy #ktprecon #sqlpass Parts of database must all be at the same point in time as primary filegroup&#8230; no problem.       11/2/09 10:08 PM http://twitter.com/PaulRandal/statuses/5374338657 #ktprecon    PaulRandal: #sqlpass Q: How to make system gen&#8217;d stats persist after a restart? A: they are always persisted in the primary FG.         11/2/09 10:10 PM http://twitter.com/PaulRandal/statuses/5374383621 #sqlpass  PaulRandal: #ktprecon #sqlpass How are auto-gen&#8217;d stats names generated? http://bit.ly/14nc0w                 11/2/09 10:18 PM http://twitter.com/PaulRandal/statuses/5374593689 #ktprecon  #sqlpass  PaulRandal: #ktprecon #sqlpass Stats are *always* at the table level. Partitioning has *no* benefit as far as stats are concerned. Even in SS2008.    11/2/09 10:53 PM http://twitter.com/PaulRandal/statuses/5375430211 #ktprecon  #sqlpass  PaulRandal: #ktprecon #sqlpass 2008 filtered stats != poor-man&#8217;s partition-level stats                   11/2/09 10:54 PM http://twitter.com/PaulRandal/statuses/5375440275 #ktprecon  #sqlpass  PaulRandal: Apparently my #sqlpass worth today is limited to tweeting from #ktprecon, and holding her used teabags. Very humbling        11/2/09 11:05 PM http://twitter.com/PaulRandal/statuses/5375710177 #sqlpass  #ktprecon PaulRandal: @plitwin #sqlpass #ktprecon She&#8217;ll get the same treatment in my Friday post-con &#8211; it goes both ways.           11/2/09 11:09 PM http://twitter.com/PaulRandal/statuses/5375810255 #sqlpass  #sqlpass  PaulRandal: #ktprecon #sqlpass Filtered indexes and filtered stats might become seriously out-of-date http://bit.ly/1knEE2          11/2/09 11:41 PM http://twitter.com/PaulRandal/statuses/5376600563 #ktprecon  #sqlpass  PaulRandal: #sqlpass One of the joys of co-presenting is watching Kimberly trying to draw on-screen using ZoomIt            11/2/09 11:49 PM http://twitter.com/PaulRandal/statuses/5376778832 #sqlpass  PaulRandal: #ktprecon #sqlpass Does order of columns in WHERE clause affect index choice? No. (unless you&#8217;ve got, say, 50 conditions)       11/2/09 11:50 PM http://twitter.com/PaulRandal/statuses/5376814447 #ktprecon  #sqlpass  PaulRandal: #ktprecon #sqlpass I love hearing UNION described as &#8220;set, set squish&#8221;                    11/3/09 12:10 AM http://twitter.com/PaulRandal/statuses/5377285038 #ktprecon  #sqlpass  PaulRandal: #ktprecon #sqlpass [...]]]></description>
			<content:encoded><![CDATA[<p>If you didn’t make it out to the PASS Summit then you missed out on a lot of great content.  If you’re not on twitter and following some of SQL Server’s best and or rowdiest than you’re missing a lot.  And if you didn’t follow Paul Randal while he was tweeting from the session he and Kimberly L. Tripp presented then you missed a great refersher course on SQL fundamentals that are critical to your success in this field.</p>
<p>The challenge of dealing with great content burried in tweets is figuring out how to capture that information in a way you can reference it later. I took a queue from of Bruce Payette’s book <strong><em>Windows PowerShell in Action </em></strong>and decided I&#8217;d try tackling this problem. </p>
<p>I started by visiting the <a href="http://www.twitter.com/PaulRandal">PaulRandal</a> twitter page. If you just wanted to download his last 20 tweets you could just use the RSS feed: <a href="http://twitter.com/statuses/user_timeline/36394357.rss">http://twitter.com/statuses/user_timeline/36394357.rss</a> .  How do you get the others? I got around the 20 tweet limitation by  favorite-ing Paul’s tweets starting at the beginning of the conference and then working my way toward the current date:</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="655" height="439" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://sqlvariant.com//BlogSupport/Images/TwitterRSSFavorites/FavoriteTweet.jpg" /><embed type="application/x-shockwave-flash" width="655" height="439" src="http://sqlvariant.com//BlogSupport/Images/TwitterRSSFavorites/FavoriteTweet.jpg"></embed></object></p>
<p>Every time I selected 20 of Paul’s tweets as a favorite I just ran this PowerShell script and appended it to a file that I was storing them in. </p>
<p> (<span style="color: #339966;">[xml]</span> (<span style="color: #0000ff;">new-object</span> <span style="color: #800080;">net</span>.<span style="color: #800080;">webclient</span>).DownloadString(<span style="color: #800000;">&#8220;</span><a href="http://twitter.com/favorites/76699854.rss&quot;)).rss.channel.item"><span style="color: #800000;">http://twitter.com/favorites/76699854.rss&#8221;</span>)).rss.channel.item</a> | <span style="color: #0000ff;">format</span><span style="color: #0000ff;">-</span><span style="color: #0000ff;">table</span> -autosize <span style="color: #800080;">description</span>, <span style="color: #800080;">pubDate</span>, <span style="color: #800080;">link</span> &gt;&gt; <span style="color: #800080;">PaulRandal</span>.<span style="color: #800080;">txt</span></p>
<p>After that I used SSIS to load them in a SQL db and help me clear out a few of the tweets that would be of little use without the other half of the conversation and what not. </p>
<p>I did learn a couple of interesting PowerShell quirks during this process.  The first is that your output is truncated based on your available screen size.  I began writing this script while running the PowerShell command in a 1280 x 1024 screen.  When my output was restricted I took a chance and tried running it on my laptop where the resolution is ste to 1920 x 1200. Running the download at a higher resolution was good enough to solve problem. (I haven’t yet found out why PowerShell kept trying to truncate in the first place. If you have ideas on this feel free to use the comments.)  The second was seeing the real differenece between the “&gt;&gt;”  and &#8220;&gt;&#8221; operators.  By using a double “&gt;&gt;” instead of a single “&gt;” I was able to append my output instead of completely replace it every time I ran my script.  Next time I’ll figure out how to pump it straight into a table so that I can skip the SSIS step.</p>
<p>Finally here’s what I ended up with:</p>
<table border="0" cellspacing="0" cellpadding="0" width="1503">
<colgroup span="1">
<col span="1" width="80"></col>
<col span="1" width="816"></col>
<col span="1" width="118"></col>
<col span="1" width="319"></col>
<col span="1" width="170"></col>
</colgroup>
<tbody>
<tr height="21">
<td width="80" height="21"><strong>Handle</strong></td>
<td width="816"><strong>Tweet</strong></td>
<td width="118"><strong>TweetDate</strong></td>
<td width="319"><strong>TweetLink</strong></td>
<td width="170"><strong>HashTags</strong></td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>And we&#8217;re on &#8211; pretty packed room here in our pre-con &#8211; just shy of 100. #sqlpass                </td>
<td>11/2/09 4:38 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5366919942</td>
<td>#sqlpass                </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#sqlpass Let&#8217;s make the hashtag for our indexing precon #ktprecon &#8211; I&#8217;ll watch both.               </td>
<td>11/2/09 4:56 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5367318129</td>
<td>#sqlpass  #ktprecon </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>Question from #sqlpass: Ever a use for heaps? A: Not really. E.g. incoming clickstream temp storage            </td>
<td>11/2/09 4:58 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5367371468</td>
<td>#sqlpass: </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#sqlpass Either that or Kimberly&#8217;s jokes really *are* bad, and I&#8217;m just laughing because I have to (being married to her) <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />      </td>
<td>11/2/09 5:01 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5367439309</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass Q: why do SELECT COUNT(*) of a heap with fwded records generate extra IOs?             </td>
<td>11/2/09 5:14 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5367732804</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass A: because the Storage Engine will only process fwded records when it finds them from a fwding record      </td>
<td>11/2/09 5:14 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5367744740</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@DBA_hole #ktprecon #sqlpass Yes (unless you specifically ask for a nonclustered primary key)             </td>
<td>11/2/09 5:19 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5367850801</td>
<td>#ktprecon  #ktprecon </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@DBA_hole #ktprecon #sqlpass But not a drop/recreate. It&#8217;s a create of clustered index + drop of heap. Semantic, but important difference.  </td>
<td>11/2/09 5:20 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5367869544</td>
<td>#ktprecon  #ktprecon </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass Our wonderful attendees&#8230; <a href="http://pic.gd/b17455">http://pic.gd/b17455</a>                    </td>
<td>11/2/09 5:24 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5367969054</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass Kimberly in mid-sentence&#8230; isn&#8217;t she cute? <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  <a href="http://pic.gd/ba2662">http://pic.gd/ba2662</a>               </td>
<td>11/2/09 5:26 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5368012672</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass Ola Hallengren&#8217;s *wonderful* db maintenance script: <a href="http://bit.ly/3R5OUv">http://bit.ly/3R5OUv</a>              </td>
<td>11/2/09 5:35 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5368219637</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@sqlinsaneo They&#8217;re not real seagulls &#8211; they&#8217;re MS-controlled robots #sqlpass                 </td>
<td>11/2/09 5:37 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5368256080</td>
<td>#sqlpass                 </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@buckwoody I&#8217;m trying to avoid looking at you &#8211; too embarrassed after what happened to us last night in that phone booth #sqlpass    </td>
<td>11/2/09 5:42 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5368367982</td>
<td>#sqlpass    </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass Alternative to shrink: <a href="http://bit.ly/43PQI">http://bit.ly/43PQI</a>                     </td>
<td>11/2/09 5:54 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5368638484</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@DBA_hole #ktprecon #sqlpass Depends on your I/O subsystem, filegroup layout, HA/DR strategy&#8230; may be more mgmt probs than gains    </td>
<td>11/2/09 6:04 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5368853068</td>
<td>#ktprecon  #ktprecon </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#sqlpass Please refill the coffee in the speaker room (and have someone check regularly&#8230;) thanks!            </td>
<td>11/2/09 6:38 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5369614171</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@DonKirkham #sqlpass backup/restore does not reclaim space (or do anything else to the db). Only way to reclaim is some form of shrink.   </td>
<td>11/2/09 6:41 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5369662274</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@DonKirkham See <a href="http://bit.ly/43PQI">http://bit.ly/43PQI</a> for an alternative for you.                     </td>
<td>11/2/09 6:51 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5369891151</td>
<td>NULL</td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@ktegels Because an existing filegroup has data files &#8211; a FS filegroup is a pointer to the root of the NTFS data container      </td>
<td>11/2/09 6:52 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5369909736</td>
<td>NULL</td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass How expensive are page splits in terms of transaction log? <a href="http://bit.ly/MqUgU">http://bit.ly/MqUgU</a>            </td>
<td>11/2/09 7:03 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5370157274</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass Do page splits ever roll back? No: script to prove it: <a href="http://bit.ly/2IgMM3">http://bit.ly/2IgMM3</a>             </td>
<td>11/2/09 7:04 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5370177946</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass Demo scripts (and companion content for the internals book chapter) are at <a href="http://bit.ly/42zJ4c">http://bit.ly/42zJ4c</a>        </td>
<td>11/2/09 7:10 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5370304102</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>Audience perspective: RT @joewebb: Live from #ktprecon at #sqlpass.  <a href="http://twitpic.com/o13um">http://twitpic.com/o13um</a>             </td>
<td>11/2/09 7:12 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5370346695</td>
<td>#ktprecon  #sqlpass</td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass Kimberly dissing DBCC commands while I&#8217;m on stage next to her? Not a smart move! <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />            </td>
<td>11/2/09 7:17 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5370471853</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass OH from Kimberly: &#8220;The key points are&#8230;. really just the key points.&#8221; Very astute observation there dear <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />     </td>
<td>11/2/09 7:45 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5371086548</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@ChiragRoy #ktprecon #sqlpass It depends <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  Wait until she talks about indexing strategies this afternoon.          </td>
<td>11/2/09 7:48 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5371143932</td>
<td>#ktprecon   </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@AndyLeonard #sqlpass #ktprecon She&#8217;ll never see it &#8211; she doesn&#8217;t tweet much &#8211; I&#8217;m safe <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />               </td>
<td>11/2/09 7:49 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5371159601</td>
<td>#sqlpass  #ktprecon </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#sqlpass People.. the answer is always &#8220;it depends&#8221;. Apart from if the question is &#8216;should auto-shrink be turned on?&#8217;.       </td>
<td>11/2/09 7:58 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5371365926</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@datachick My other favorite answer is &#8220;12&#8243; and then watch the mystified expressions. #sqlpass             </td>
<td>11/2/09 8:01 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5371421542</td>
<td>#sqlpass             </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#sqlpass L U N C H    T I M E! #ktprecon We&#8217;ll be back to cover more incredible indexing info (and on-stage (verbal) spousal abuse! <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />    </td>
<td>11/2/09 8:03 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5371476694</td>
<td>#sqlpass  #ktprecon </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@DonKirkham Ah &#8211; no solution for that &#8211; maybe a 3rd-party backup/restore tool?                 </td>
<td>11/2/09 8:52 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5372567849</td>
<td>NULL</td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass Once more into the breach, dear friends, once more&#8230;.  back after lunch with the KT Indexing Show       </td>
<td>11/2/09 9:05 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5372866600</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass Don&#8217;t INCLUDE LOB columns in NC indexes. It creates a whole extra copy of the LOB data. Not good.       </td>
<td>11/2/09 9:10 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5372989895</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass And don&#8217;t put an index on every column. One of the worst things you can do.             </td>
<td>11/2/09 9:13 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5373037864</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@SQLCraftsman Oh yeah. Confusing unto and into always gets me into unto-ward trouble.               </td>
<td>11/2/09 9:16 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5373123933</td>
<td>NULL</td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass What is a &#8216;seekable&#8217; index? An index with keys that can be used in a left-based subset to match a search argument.   </td>
<td>11/2/09 9:23 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5373277154</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon @sqlpass What order should the NC index key columns be in? It depends&#8230; <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />                </td>
<td>11/2/09 9:24 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5373306090</td>
<td>#ktprecon </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass So far Kimberly&#8217;s answered &#8220;It depends&#8221; 15 times&#8230;                   </td>
<td>11/2/09 9:26 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5373359667</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#sqlpass Q I get asked: query perf dropping, what happened? If it slowly drops, fragmentation. If it drops off a cliff, stats. Commonly.  </td>
<td>11/2/09 9:35 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5373562535</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@ChiragRoy #ktprecon #sqlpass Parts of database must all be at the same point in time as primary filegroup&#8230; no problem.      </td>
<td>11/2/09 10:08 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5374338657</td>
<td>#ktprecon   </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#sqlpass Q: How to make system gen&#8217;d stats persist after a restart? A: they are always persisted in the primary FG.        </td>
<td>11/2/09 10:10 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5374383621</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass How are auto-gen&#8217;d stats names generated? <a href="http://bit.ly/14nc0w">http://bit.ly/14nc0w</a>                </td>
<td>11/2/09 10:18 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5374593689</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass Stats are *always* at the table level. Partitioning has *no* benefit as far as stats are concerned. Even in SS2008.   </td>
<td>11/2/09 10:53 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5375430211</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass 2008 filtered stats != poor-man&#8217;s partition-level stats                  </td>
<td>11/2/09 10:54 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5375440275</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>Apparently my #sqlpass worth today is limited to tweeting from #ktprecon, and holding her used teabags. Very humbling <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />       </td>
<td>11/2/09 11:05 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5375710177</td>
<td>#sqlpass  #ktprecon</td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@plitwin #sqlpass #ktprecon <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  She&#8217;ll get the same treatment in my Friday post-con &#8211; it goes both ways.          </td>
<td>11/2/09 11:09 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5375810255</td>
<td>#sqlpass  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass Filtered indexes and filtered stats might become seriously out-of-date <a href="http://bit.ly/1knEE2">http://bit.ly/1knEE2</a>         </td>
<td>11/2/09 11:41 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5376600563</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#sqlpass One of the joys of co-presenting is watching Kimberly trying to draw on-screen using ZoomIt <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />           </td>
<td>11/2/09 11:49 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5376778832</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass Does order of columns in WHERE clause affect index choice? No. (unless you&#8217;ve got, say, 50 conditions)      </td>
<td>11/2/09 11:50 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5376814447</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass I love hearing UNION described as &#8220;set, set squish&#8221;                   </td>
<td>11/3/09 12:10 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5377285038</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass Over-indexing is worse than under-indexing. Err on the side of fewer indexes always.           </td>
<td>11/3/09 12:16 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5377431451</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass OH: keep the search arguments in the WHERE clause and the join arguments in the FROM clause         </td>
<td>11/3/09 12:18 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5377480586</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass For OLTP or OLTP/DSS combo, you want to try to cover the aggregate. INCLUDE the columns you&#8217;re aggregating.     </td>
<td>11/3/09 12:22 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5377572922</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass and GROUP BY the key. E.g. SUM(sales) by customer                   </td>
<td>11/3/09 12:22 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5377583436</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass key would be customer, INCLUDE would be sales. Otherwise an unordered aggregate needs to be done. Slooooooow.    </td>
<td>11/3/09 12:23 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5377606311</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass Indexed views whitepaper <a href="http://bit.ly/22lStl">http://bit.ly/22lStl</a>                    </td>
<td>11/3/09 12:29 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5377739599</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass Whitepaper comparing heaps and clustered indexes <a href="http://bit.ly/HPonN">http://bit.ly/HPonN</a>               </td>
<td>11/3/09 12:30 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5377761144</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass Database Tuning Advisor whitepaper <a href="http://bit.ly/2ykHEI">http://bit.ly/2ykHEI</a>                  </td>
<td>11/3/09 12:32 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5377819794</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#ktprecon #sqlpass Craig Freedman&#8217;s blog on index_operational_stats <a href="http://bit.ly/BVcIV">http://bit.ly/BVcIV</a>               </td>
<td>11/3/09 12:35 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5377897936</td>
<td>#ktprecon  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>Today Kimberly and I are the embodiment of &#8216;it depends&#8217;. Catch us at lunchtime! #sqlpass              </td>
<td>11/3/09 6:30 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5398059867</td>
<td>#sqlpass              </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>That picture&#8217;s on my FB page too <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  RT @robboek: @BrentO just put up a very flattering picture of @PaulRandal #sqlpass       </td>
<td>11/3/09 11:57 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5405773692</td>
<td>#sqlpass       </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@MidnightDBA #sqlpass 1000 is a number I made up when back at MS, but it only applies if the table is in memory. Otherwise, sure, defrag.  </td>
<td>11/4/09 12:06 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5406019739</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#sqlpass Just like the &amp;lt;10% nothing, 10-30% defrag, 30%+ rebuild. I made those numbers up too as people wanted *some* guidance. YMMV.  </td>
<td>11/4/09 12:10 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5406101235</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@GFritchey Hope you didn&#8217;t mind me commenting on the tweets coming from your session!               </td>
<td>11/4/09 12:53 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5407198123</td>
<td>NULL</td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@GFritchey <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  I always like to &#8216;fess up about the BOL numbers/guidance about defragging.              </td>
<td>11/4/09 1:01 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5407384733</td>
<td>NULL</td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@kbriankelley @SQLSarg #sqlpass Absolutely disagree for user DBs.                    </td>
<td>11/4/09 2:08 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5409027866</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@SQLSarg @kbriankelley #sqlpass and for tempdb, start with #files = 1/4-1/2 #cores IF seeing page latch contention (not page IO latch)   </td>
<td>11/4/09 2:09 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5409043381</td>
<td>#sqlpass</td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@kbriankelley @SQLSarg #sqlpass see <a href="http://bit.ly/vNMLv">http://bit.ly/vNMLv</a>                       </td>
<td>11/4/09 2:09 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5409052369</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#sqlpass For me best thing about this PASS is mting all Tweeps I&#8217;ve gotten to know over last 6 mths. We have a *rocking* community!    </td>
<td>11/4/09 3:47 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5411356916</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#sqlpass In a good way, of course. Well, maybe except @BrentO and @sqlrockstar&#8230;. ;-D               </td>
<td>11/4/09 3:50 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5411421298</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>Snotty in Seattle. Cold is kicking my butt again, offline now to veg in front of TV b4 Logging&amp;Recovery spotlight at #sqlpass in the a.m.  </td>
<td>11/4/09 3:55 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5411539260</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>Wow &#8211; all the #Muppets videos have gone from YouTube (under litigation threat from WMG) &#8211; no more #Manamana! How sad <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' />       </td>
<td>11/4/09 4:04 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5411732262</td>
<td>#Muppets  #Manamana</td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#sqlpass Understand Logging and Recovery? Completely? If not, come to my spotlight this morning at 10.15 in 2AB.        </td>
<td>11/4/09 4:08 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5423467554</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@AndyLeonard @sqlagentman It&#8217;s called job security. Make up numbers while at MS, get paid to explain them once I leave. Simple! ;-D #sqlpass </td>
<td>11/4/09 4:09 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5423487218</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@AndyLeonard #sqlpass Don&#8217;t blame me &#8211; I didn&#8217;t make up the schedule!                                                                        </td>
<td>11/4/09 4:13 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5423581653</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@buckwoody A kilt will be on show.                                                                                                           </td>
<td>11/4/09 4:13 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5423588057</td>
<td>NULL</td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>Had great fun doing my logging/recovery session this morning. I&#8217;ve got some much deeper log internals blog posts lined up too. #sqlpass      </td>
<td>11/4/09 10:56 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5433042824</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@way0utwest You may have a kilt, but you also have a pink cowboy hat. I worry about you Steve&#8230; #sqlpass                                    </td>
<td>11/4/09 11:58 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5434603222</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>Damn right! bwin have a rocking SQL setup. RT @aspiringgeek: DBCC should be done everyday. No, not @paulrandal, bwin&#8217;s VLDB&#8217;s DBA #sqlpass   </td>
<td>11/4/09 11:59 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5434631011</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>Helping Kimberly thread the wireless mic under her top #sqlpass #passawesomeness <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />                                                          </td>
<td>11/5/09 12:22 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5435227503</td>
<td>#sqlpass  #passawesomeness </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@SQLCraftsman Just ask @BuckWoody about the time he was almost arrested in Leavenworth with me&#8230;. #sqlpass                                  </td>
<td>11/5/09 12:24 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5435267079</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>In Kimberly&#8217;s Covering Indexes Spotlight session &#8211; 4C1-2 #sqlpass                                                                            </td>
<td>11/5/09 12:28 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5435383697</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>Kimberly on stage #sqlpass <a href="http://pic.gd/ad90dc">http://pic.gd/ad90dc</a>                                                                                              </td>
<td>11/5/09 12:35 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5435542229</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>RT @sarahspace: How I explain what it is like to be a DBA:  DBA is the sexiest profession there is this side of being a stripper #sqlpass    </td>
<td>11/5/09 12:45 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5435797449</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>Now sitting next to @sqlfool in @kimberlyltripp&#8217;s session #sqlpass                                                                           </td>
<td>11/5/09 12:46 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5435836985</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@kimberlyltripp&#8217;s Tipping Point blog posts r @ <a href="http://bit.ly/2yStzr">http://bit.ly/2yStzr</a> #sqlpass You&#8217;d be amazed how selective a query must be to use an index.  </td>
<td>11/5/09 12:50 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5435945322</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@t_burger @kimberlyltripp&#8217;s deck is up on site but may not have made it to the download section yet. Don&#8217;t worry, it will be. #sqlpass       </td>
<td>11/5/09 12:54 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5436032143</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@DevSQL She also has roadrunnerkt and I have roadrunnerpr. I&#8217;ve got another one called roadkill <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  #sqlpass                                 </td>
<td>11/5/09 12:55 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5436070845</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@tjaybelt I think @kimberlyltripp just rocks full-stop <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />                                                                                    </td>
<td>11/5/09 1:00 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5436179324</td>
<td>NULL</td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@aspiringgeek She&#8217;s sitting next to me &#8211; just showed her that tweet #sqlpass                 </td>
<td>11/5/09 1:00 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5436195302</td>
<td>#sqlpass                 </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>Latest version of @kimberlyltripp&#8217;s sp_helpindex2 script is at <a href="http://bit.ly/3WjfSJ">http://bit.ly/3WjfSJ</a> #sqlpass             </td>
<td>11/5/09 1:04 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5436286609</td>
<td>#sqlpass             </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>He has amazing body-hair&#8230;. RT @janhonenj: #sqlpass @BuckWoody is claiming he knows something about shampoo. I&#8217;m not sure I believe him.  </td>
<td>11/5/09 1:06 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5436336983</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@Kimberlyltripp managed to go 6 whole seconds without saying &#8216;it depends&#8217; after challenging herself not to. Nice. #sqlpass      </td>
<td>11/5/09 1:09 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5436412870</td>
<td>#sqlpass      </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>Do not just automatically put an index on every column #sqlpass                     </td>
<td>11/5/09 1:13 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5436521435</td>
<td>#sqlpass                     </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>Over-indexing is usually worse than under-indexing &#8211; think of the overhead of maintaining all those unused indexes&#8230; #sqlpass     </td>
<td>11/5/09 1:14 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5436540474</td>
<td>#sqlpass     </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>Covering: best done cleverly, correctly, and concisely. @kimberlyltripp was in an alliterative mood, obviously. #sqlpass      </td>
<td>11/5/09 1:16 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5436603907</td>
<td>#sqlpass      </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@BrentO, *you* of all people organized a breakfast *without* #bacon?!?! RT @lotsahelp: @BrentO going to remember the #bacon? #sqlpass   </td>
<td>11/5/09 1:26 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5436850100</td>
<td>#bacon?!?!  #sqlpass</td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>Chugging down Hall&#8217;s cough sweets to try to avoid a cacophony of coughing in the covering session #sqlpass          </td>
<td>11/5/09 1:27 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5436883380</td>
<td>#sqlpass          </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>If your stats are out of date, it might not matter how good your indexes are &#8211; SQL may not be able to figure out to use them #sqlpass   </td>
<td>11/5/09 1:30 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5436960619</td>
<td>#sqlpass   </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>OH from @kimberlyltripp: I want you to stop caring #sqlpass                      </td>
<td>11/5/09 1:40 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5437224158</td>
<td>#sqlpass                      </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>You can get the Credit db that @kimberlyltripp was using in the session from <a href="http://bit.ly/1PHPKi">http://bit.ly/1PHPKi</a> #sqlpass          </td>
<td>11/5/09 1:43 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5437302767</td>
<td>#sqlpass          </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>OMG these chairs are incredibly uncomfortable &#8211; parts of my anatomy are asleep and sore! #sqlpass            </td>
<td>11/5/09 1:45 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5437340876</td>
<td>#sqlpass            </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>Using indexed views wps <a href="http://bit.ly/22lStl">http://bit.ly/22lStl</a> (2005) and <a href="http://bit.ly/3LpZnT">http://bit.ly/3LpZnT</a> (2008). Don&#8217;t go crazy with them though #sqlpass     </td>
<td>11/5/09 1:58 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5437695804</td>
<td>#sqlpass     </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>My latest TechNet Magazine article is out on web &#8220;Recovering from Disasters Using Backups&#8221; <a href="http://bit.ly/14XK1l">http://bit.ly/14XK1l</a> #sql #sqlserver #sqlpass  </td>
<td>11/5/09 4:35 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5453506227</td>
<td>#sql #sqlserver #sqlpass</td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>Yeah! RT @sqlbelle: Yup! Agreed! RT @kbriankelley: @sqlbelle That&#8217;s a shame. You&#8217;ll get more DR info out of a @PaulRandal session. #sqlpass  </td>
<td>11/5/09 5:17 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5454526890</td>
<td>#sqlpass  </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>We spent ton of time at end of 2005 dev reducing data/inst cache misses &#8211; very fiddly, gnarly work, but fun! #sqlpass                        </td>
<td>11/5/09 5:44 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5455166160</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>I always explain that the NULL bitmap in a record is one big cpu cache miss prevention mechanism #sqlpass                                    </td>
<td>11/5/09 5:46 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5455200176</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>Here&#8217;s the MIT paper, it&#8217;s a good read: Materialization Strategies in a Column-Oriented DBMS <a href="http://bit.ly/2q4Nu0">http://bit.ly/2q4Nu0</a> #sqlpass                   </td>
<td>11/5/09 6:17 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5455915997</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>You can actually download MITs column store database engine source code and play around with it too <a href="http://bit.ly/245xT6">http://bit.ly/245xT6</a> #sqlpass            </td>
<td>11/5/09 6:24 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5456076673</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>Me too! RT @AndyLeonard: Hey #sqlpass! I will be at the PASS Bookstore at noon to sign books and answer questions.                           </td>
<td>11/5/09 6:53 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5456739889</td>
<td>#sqlpass! </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@sqlfool I&#8217;ll be wearing my &#8216;it depends&#8217; t-shirt again today, just for you. See you at lunch at the bookstore.                               </td>
<td>11/5/09 7:09 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5457110526</td>
<td>NULL</td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>Came home from #sqlpass to prep for tomorrow&#8217;s post-con/convalesce &#8211; lots of #bacon and eggs for lunch mmmmmmm                               </td>
<td>11/5/09 9:34 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5460564441</td>
<td>#sqlpass  #bacon</td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@aspiringgeek Surely they&#8217;re not advising that as a generalization? #sqlpass                                                                 </td>
<td>11/5/09 10:02 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5461290973</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@simon_sabin Yup, -E makes ind creates/rebuilds alloc multiple extents when round-robin-ing. Didn&#8217;t realize @aspiringgeek&#8217;s context #sqlpass </td>
<td>11/5/09 10:08 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5461450239</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@hpebley3 #sql the database with the ID in the message is shutdown and can&#8217;t be started for some reason.                                     </td>
<td>11/5/09 11:01 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5462793689</td>
<td>#sql </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>Leave it on for *all* DBs RT @sqlbelle: Leave autogrow on for #sharepoint dbs  . It is like your catastrophic insurance policy #SQLPASS      </td>
<td>11/5/09 11:02 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5462805846</td>
<td>#sharepoint  #SQLPASS</td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#sqlpass if anyone&#8217;s brave enough, ask @BuckWoody to tell the story of the time we were arrested in Leavenworth when he did a strip-tease&#8230; </td>
<td>11/5/09 11:06 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5462923584</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@PaulRandal #sqlpass &#8230; during the winter yodeling competition.                                                                             </td>
<td>11/5/09 11:07 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5462941379</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#sqlpass And btw, @BuckWoody won the yodeling competition. Very scary. Never go on vacation with that man.                                   </td>
<td>11/5/09 11:10 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5463008889</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@AndyLeonard Tell him &#8220;No, no, the other one &#8211; the burly one that grabbed me&#8221;                                                                </td>
<td>11/5/09 11:11 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5463038560</td>
<td>NULL</td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#sqlpass Ok, ask @BuckWoody why he&#8217;s not allowed on any Sound Transit public buses any more&#8230; there&#8217;s a story.                              </td>
<td>11/5/09 11:12 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5463065739</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#sqlpass When they arrested @BuckWoody, he tried to claim he was Bill Gates. But the cop knew Bill had more hair.                            </td>
<td>11/5/09 11:13 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5463093029</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#sqlpass Twitter is wonderful, interacting with (well, derailing) sessions remotely! Maybe @BuckWoody and I should co-present one next time? </td>
<td>11/5/09 11:15 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5463145994</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@AndyLeonard @BuckWoody&#8217;s Kung Fu is weaker than mine&#8230; #sqlpass                                                                            </td>
<td>11/5/09 11:17 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5463184554</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>Hmm &#8211; he might &#8216;dress up&#8217; again. RT @mrdenny: I think @PaulRandal and @buckwoody need to come to the bar with us tonight.  #sqlpass          </td>
<td>11/5/09 11:19 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5463230998</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#sqlpass Someone tell @BuckWoody his wife called to say he&#8217;d forgotten his meds again this morning and could I take care of him?             </td>
<td>11/5/09 11:24 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5463361106</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#sqlpass and whatever you do, don&#8217;t feed @BuckWoody&#8217;s psychoses by letting him talk to an audience &#8211; he gets delusions of grandeur.          </td>
<td>11/5/09 11:25 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5463387065</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#sqlpass OMG &#8211; the gerbil story! (Well, multiple gerbils were involved actually) @BuckWoody&#8217;s daughter was really annoyed. Someone ask him.. </td>
<td>11/5/09 11:27 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5463431830</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#sqlpass Just imagine @BuckWoody, dressed like a pest-control guy, tripping out on who-knows-what, running around a house after gerbils&#8230;   </td>
<td>11/5/09 11:30 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5463505072</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@AaronBertrand That&#8217;s because of the Cease and Desist letter @BuckWoody had from the Animal Control folks #sqlpass                           </td>
<td>11/5/09 11:32 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5463553322</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@AndyLeonard That reminds me &#8211; you should see tricks @BuckWoody can do with whole olives and cocktail sticks, using just his teeth #sqlpass  </td>
<td>11/5/09 11:34 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5463602738</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>That&#8217;s right. Never trust @BuckWoody. Never. RT @mrdenny: @AndyLeonard @PaulRandal I&#8217;m sure that it is a trick. #sqlpass                     </td>
<td>11/5/09 11:35 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5463619541</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#sqlpass For finale, someone ask @BuckWoody if he can do last 5 minutes of his session after removing all his false teeth&#8230;he&#8217;s good at it! </td>
<td>11/5/09 11:37 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5463678735</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>And you wonder why he gets arrested&#8230;. RT @SQLRockstar: @buckwoody has $5 in his pocket AND someone else&#8217;s pants on #woodyfacts #sqlpass    </td>
<td>11/5/09 11:41 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5463773956</td>
<td>#woodyfacts  #sqlpass</td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>I&#8217;m proud I had most insults from @BuckWoody. I guess. RT @sqlagentman: New blog post: Buck Woody Has Issues <a href="http://bit.ly/3MSRpO">http://bit.ly/3MSRpO</a> #sqlpass   </td>
<td>11/5/09 11:52 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5464044193</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@TimCaylor #sqlpass will be in Seattle Nov 8-11 2010                                                                                         </td>
<td>11/5/09 11:52 PM</td>
<td>http://twitter.com/PaulRandal/statuses/5464051949</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@BuckWoody and I just agreed to do a joint session next year &#8211; and we&#8217;ll both wear kilts! Be afraid&#8230; be very afraid&#8230;. #sqlpass           </td>
<td>11/6/09 12:29 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5464941037</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#1 tip for speakers I saw this year at #sqlpass &#8211; get a clicker so you can move around the stage more freely.                                </td>
<td>11/6/09 12:31 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5464979616</td>
<td>#1  #sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>Blog: <a href="http://bit.ly/14nc0w">http://bit.ly/14nc0w</a> RT @GFritchey: WA in system stats stands for Washington state. From @Paulrandal via Gail Shaw. #sqlpass           </td>
<td>11/6/09 12:35 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5465099051</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>Err, Scotland? <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  RT @joewebb: where does one buy a kilt? #sqlpass                                                                          </td>
<td>11/6/09 12:48 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5465408175</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@joewebb It&#8217;s a neat trick. In my spotlight last year I showed how to change them in 2005+ too, in dire circumstances <img src='http://sqlvariant.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />                     </td>
<td>11/6/09 12:50 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5465461390</td>
<td>NULL</td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>See blog TechEd Demo: Using the SQL 2005 Dedicated Admin Connection to fix Msg 8992: corrupt system tables <a href="http://bit.ly/njh9B">http://bit.ly/njh9B</a> #sqlpass      </td>
<td>11/6/09 12:52 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5465503209</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>Any Tweeps coming to our disaster recovery #sqlpass post-con tomorrow?                                                                       </td>
<td>11/6/09 1:01 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5465724325</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>#sqlpass isn&#8217;t a conference, it&#8217;s one big SQL fun-fest with a bunch of new and old friends. What a damn good time!                           </td>
<td>11/6/09 1:04 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5465784262</td>
<td>#sqlpass </td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>@JustAGuy0479 Cool &#8211; see you tomorrow! Are you the guy I was supposed to slap if he fell asleep in KLT&#8217;s session yesterday?                  </td>
<td>11/6/09 1:17 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5466115284</td>
<td>NULL</td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>KLT&#8217;s blog post <a href="http://bit.ly/1knEE2">http://bit.ly/1knEE2</a> RT @GFritchey: OH For filtered statistics, auto update of stats is useless. Do it yourself. &#8211; Gail Shaw </td>
<td>11/6/09 1:30 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5466422479</td>
<td>NULL</td>
</tr>
<tr height="20">
<td height="20">PaulRandal:</td>
<td>Our house&#8230; RT @sqlbelle: #sqlpass feels like *home* ie where else can you find a place where everyone does some kind of SQL Server work    </td>
<td>11/6/09 1:54 AM</td>
<td>http://twitter.com/PaulRandal/statuses/5466999689</td>
<td>#sqlpass </td>
</tr>
</tbody>
</table>
<p>And here&#8217;s the whole list in a more readable format:<br />
<a href="http://sqlvariant.com//BlogSupport/Images/TwitterRSSFavorites/PaulRandalPASS2009blog.xlsx">http://sqlvariant.com/BlogSupport/Images/TwitterRSSFavorites/PaulRandalPASS2009blog.xlsx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sqlvariant.com/wordpress/index.php/2009/11/using-powershell-to-archive-twitter-feeds-preserving-the-wisdom-of-paul-randal/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PowerShell 2.0 for XP and Up</title>
		<link>http://sqlvariant.com/wordpress/index.php/2009/10/powershell-2-0-for-xp-and-up/</link>
		<comments>http://sqlvariant.com/wordpress/index.php/2009/10/powershell-2-0-for-xp-and-up/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 15:10:21 +0000</pubDate>
		<dc:creator>Aaron Nelson</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://sqlvariant.com/wordpress/?p=68</guid>
		<description><![CDATA[If you haven&#8217;t heard the news, PowerShell 2.0 for Windows XP, Windows Server 2003, Vista, and Windows Server 2008 R1 has now been released. This is huge.  Especially for SQL folks. It&#8217;s huge because  I can once again share my PowerShell scripts with colleagues who use different operating systems.   More on why it&#8217;s huge here:  Halr9000.com Where Can I get it?!?!  Right here: http://support.microsoft.com/kb/968929 I&#8217;m a SQL Server DBA, why do I care about PowerShell?..   The other day one of the Sys. Admins. came to me and asked me how large our data files are so that he could calculate the drive spaced need for migrating to our new SAN.  I of course dropped what I was doing to gather this info for him.  Now I went through SQL to get the info but because we still have a few SQL Server 2000 machines, a few of them were undercounted!  When the Sys. Admin.  compared our lists he found one discrepancy amidst the over 600 data and log files I listed.  One database only had 4 files but they were 4 massive files (100+GB).  If Only I could cross-reference this information with what the O/S thought was there!  I&#8217;m working on a recusive script to cycle through mount points and give me a system wide total.  What I’ve put together so far is a script to calculate the total the size of all the .mdf&#8217;s in any directory you point to:  cd C:\Program` Files\Microsoft` SQL` Server\MSSQL10.KATMAI\MSSQL\DATA #Change me to YOUR directory $c=0 $l=0 foreach ($f in dir *.mdf) {$c += 1; $l += $f.length} "File Count: $c" "Total size of .mdf files in Bytes: $l" Need to count your .ndf and .ldf files too? Just append a &#8220;, *.ndf&#8221; or “*.ldf”  immediately following the *.mdf Now I don&#8217;t know if a PowerShell expert would suggest this approach, I just know that I tried it on my machine and it worked! (However, if  you’re still  storing your .ndf’s and .ldf’s on the same drive let alone same directory as your .mdf files there is a whole other conversation we should have.) Oh you need to output that to a text file so that you can email it to someone?  Just change out the last two lines (the ones in brown) for this:    "File Count: $c Total size of .mdf files in Bytes: $l" &#62; c:\Temp\MydbFileSized.txt Now I know that formatting that bytes number with some commas or at least translating it into MB would be nice but that will have to wait until another post.  Until then, have fun with what you got and tell me what you need. @SQLvariant]]></description>
			<content:encoded><![CDATA[<h3>If you haven&#8217;t heard the news, <span style="color: #000080;">PowerShell 2.0 for Windows XP, Windows Server 2003, Vista, and Windows Server 2008 R1 </span>has now been released.</h3>
<h1>This is huge.  Especially for SQL folks.</h1>
<p>It&#8217;s huge because  I can once again share my PowerShell scripts with colleagues who use different operating systems.   <em>More on why it&#8217;s huge here</em>:  <a href="http://halr9000.com/article/832">Halr9000.com</a></p>
<p><span style="color: #333399;"><span style="text-decoration: underline;"><strong>Where Can I get it?!?!  Right here:</strong></span></span><br />
<a href="http://support.microsoft.com/kb/968929">http://support.microsoft.com/kb/968929</a></p>
<p><span style="color: #333399;"><span style="text-decoration: underline;"><strong>I&#8217;m a SQL Server DBA, why do I care about PowerShell?..</strong></span>  </span></p>
<p>The other day one of the Sys. Admins. came to me and asked me how large our data files are so that he could calculate the drive spaced need for migrating to our<span style="text-decoration: underline;"> </span>new<span style="text-decoration: underline;"> SAN</span>.  I of course dropped what I was doing to gather this info for him.  Now I went through SQL to get the info but because we still have a few SQL Server 2000 machines, a few of them were <span style="text-decoration: underline;">undercounted</span>!  When the Sys. Admin.  compared our lists he found one discrepancy amidst the over 600 data and log files I listed.  One database only had 4 files but they were 4 massive files (100+GB).  <em>If Only I could cross-reference this information with what the O/S thought was there!</em>  I&#8217;m working on a recusive script to cycle through mount points and give me a system wide total.  What I’ve put together so far is a script to calculate the total the size of all the .mdf&#8217;s in any directory you point to: </p>
<pre><span style="color: #0000ff;">cd </span><span style="color: #666699;">C:\Program` Files\Microsoft` SQL` Server\MSSQL10.KATMAI\MSSQL\DATA </span><span style="color: #008000;"><strong>#Change me to YOUR directory</strong></span>

<span style="color: #ff0000;">$c</span>=0
<span style="color: #ff0000;">$l</span>=0
foreach (<span style="color: #ff0000;">$f</span> in <span style="color: #0000ff;">dir </span><span style="color: #666699;">*.mdf</span>) {<span style="color: #ff0000;">$c</span> += 1; <span style="color: #ff0000;">$l</span> += <span style="color: #ff0000;">$f</span>.length}
<span style="color: #993300;">"File Count: $c"
"Total size of .mdf files in Bytes: $l"</span></pre>
<div><span style="color: #008000;"><span style="color: #000000;"><em>Need to count your .ndf and .ldf files too? Just append a </em><em>&#8220;, *.ndf&#8221; or “*.ldf” </em><em> immediately following the</em><em> </em>*.mdf<br />
Now I don&#8217;t know if a PowerShell expert would suggest this approach, I just know that I tried it on my machine and it worked! (However, <em>if  you’re still  storing your .ndf’s and .ldf’s on the same drive let alone same directory as your .mdf files there is a whole other conversation we should have.)</em></span></span></div>
<div><span style="color: #008000;"><span style="color: #000000;">Oh you need to output that to a text file so that you can email it to someone?  Just change out the last two lines (the ones in brown) for this:</span></span></div>
<div><span style="color: #008000;"><span style="color: #000000;"> </span></span><span style="color: #008000;"><span style="color: #000000;"> </span></span></div>
<pre><span style="color: #993300;">"File Count: $c Total size of .mdf files in Bytes: $l"</span> <span style="color: #808080;">&gt;</span> <span style="color: #333399;">c:\Temp\MydbFileSized.txt</span></pre>
<p>Now I know that formatting that bytes number with some commas or at least translating it into MB would be nice but that will have to wait until another post.  Until then, have fun with what you got and tell me what you need.</p>
<p>@SQL<em>variant</em></p>
]]></content:encoded>
			<wfw:commentRss>http://sqlvariant.com/wordpress/index.php/2009/10/powershell-2-0-for-xp-and-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: basic (Requested URI is rejected)

Served from: www.sqlvariant.com @ 2012-02-04 03:24:27 -->
