<?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; T-SQL</title>
	<atom:link href="http://sqlvariant.com/wordpress/index.php/category/code/t-sql-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>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>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>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>
	</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 04:14:33 -->
