<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Random thoughts by SQL DBA/System Administrator</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/sqlthoughts/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/sqlthoughts/feed.xml</link>
    <description />
    <lastBuildDate>Wed, 17 Apr 2019 03:45:57 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Powershell function to add system path</title>
      <link>https://docs.microsoft.com/archive/blogs/sqlthoughts/powershell-function-to-add-system-path</link>
      <pubDate>Fri, 12 Dec 2008 12:14:00 GMT</pubDate>
      <dc:creator><![CDATA[ayeltsov]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/sqlthoughts/2008/12/12/powershell-function-to-add-system-path/</guid>
      <description><![CDATA[Was automating some installs and noted that powershell does not have a built-in function to add path...]]></description>
      <content:encoded><![CDATA[<P>Was automating some installs and noted that powershell does not have a built-in function to add path to the system path.<BR><BR>It was an easy fix - just use [System.Environment]::SetEnvironmentVariable function.</P><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">function</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: cadetblue; FONT-FAMILY: 'Courier New'">AddSystemPaths</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">([</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: teal; FONT-FAMILY: 'Courier New'">array</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">] </SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$PathsToAdd</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">) {<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$VerifiedPathsToAdd</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: 'Courier New'">=</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">""</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">foreach</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> (</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$Path</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">in</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$PathsToAdd</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">) {<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;</SPAN></SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">if</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> (</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$Env:Path</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: 'Courier New'">-like</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"*$Path*"</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">) {<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;</SPAN></SPAN><B><SPAN style="FONT-SIZE: 10pt; COLOR: cadetblue; FONT-FAMILY: 'Courier New'">echo</SPAN></B><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Path to $Path already added"</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;</SPAN>} <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">else</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> {<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN></SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$VerifiedPathsToAdd</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: 'Courier New'">+=</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">";$Path"</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">;</SPAN><B><SPAN style="FONT-SIZE: 10pt; COLOR: cadetblue; FONT-FAMILY: 'Courier New'">echo</SPAN></B><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Path to $Path needs to be added"</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;</SPAN>} <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">if</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> (</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$VerifiedPathsToAdd</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: 'Courier New'">-ne</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">""</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">) {<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;</SPAN></SPAN><B><SPAN style="FONT-SIZE: 10pt; COLOR: cadetblue; FONT-FAMILY: 'Courier New'">echo</SPAN></B><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"Adding paths: $VerifiedPathsToAdd"</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;</SPAN>[</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: teal; FONT-FAMILY: 'Courier New'">System.Environment</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">]::</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: saddlebrown; FONT-FAMILY: 'Courier New'">SetEnvironmentVariable</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">(</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"PATH"</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">, </SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$Env:Path</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: 'Courier New'">+</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"$VerifiedPathsToAdd"</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">,</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"Machine"</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;</SPAN></SPAN><B><SPAN style="FONT-SIZE: 10pt; COLOR: cadetblue; FONT-FAMILY: 'Courier New'">echo</SPAN></B><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"Note: The new path does NOT take immediately in running processes. Only new processes will see new path."</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 10pt"><SPAN style="FONT-SIZE: 10pt; COLOR: black; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'">}</SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"></SPAN><BR>Use example:</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none" mce_keep="true">&nbsp;</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none">PS&gt; AddSystemPaths ("C:\Program Files\sd","c:\tools")<BR>&nbsp; Path to C:\Program Files\sd already added<BR>&nbsp; Path to c:\tools needs to be added<BR>Adding paths: ;c:\tools<BR>Note: The new path does NOT take immediately in running processes. Only new processes will see new path.<BR>PS&gt;</P>]]></content:encoded>
    </item>
    <item>
      <title>out-sql Powershell function - export pipeline contents to a new SQL Server table</title>
      <link>https://docs.microsoft.com/archive/blogs/sqlthoughts/out-sql-powershell-function-export-pipeline-contents-to-a-new-sql-server-table</link>
      <pubDate>Fri, 03 Oct 2008 15:15:00 GMT</pubDate>
      <dc:creator><![CDATA[ayeltsov]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/sqlthoughts/2008/10/03/out-sql-powershell-function-export-pipeline-contents-to-a-new-sql-server-table/</guid>
      <description><![CDATA[Recently I needed to take output of command-line tool and cross-reference it with information in the...]]></description>
      <content:encoded><![CDATA[<P>Recently I needed to take output of command-line tool and cross-reference it with information in the database. The tool's output was XML, and I was additionally processing it a bit with Powershell. Now, how to get that to SQL Server? </P>
<P>I searched for out-sql Powershell cmdlet or function which allows to save the pipeline data to SQL Server, and I&nbsp;could not find one. So I wrote one.</P>
<P>It did the job for me, but&nbsp;obviously it's not perfect. Specifically:</P>
<UL>
<LI>I use plain old INSERT statements - it's not the fastest method for inserting large amounts of data.&nbsp;Furthermore, I send each individual statement as a batch and an individual transaction.&nbsp;But I would not worry about it unless I insert hundreds of thousands or rows.</LI>
<LI>No explicit error handling. SQL will throw the errors if it has a problem. The drawback is that script execution won't stop on say connection open error, and will continue -&nbsp;printing an additional error for every row.</LI>
<LI>Short of dates, I save everything as NVARCHAR(MAX). I chose not to mess with integers - it was not needed for my project.</LI></UL>
<P>If you do end up using this, drop me a note on your experiences. If you do make enhancements, feel free to share with me!</P>
<P>Here's the function:</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##############################################################################<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">## out-sql.ps1<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">## by Alexey Yeltsov, Microsoft Corp.<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">## Export pipeline contents into a new SQL table<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">## Parameters:<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##&nbsp;&nbsp;&nbsp; $SqlServer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - SQL Server<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##&nbsp;&nbsp;&nbsp; $Database&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - Database name<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##&nbsp;&nbsp;&nbsp; $Table&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - Table name<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##&nbsp;&nbsp;&nbsp; $DropExisting&nbsp; - Drop $Table if it already exists and recreate it <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(default $false)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##&nbsp;&nbsp;&nbsp; $RowId&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - Add identity column named $RowId and make it a primary key. <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (default "RowID". Can pass $null if identity is not needed)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">## Examples:<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##&nbsp;&nbsp;&nbsp; <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##&nbsp;&nbsp;&nbsp; #First, load the function<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##&nbsp;&nbsp;&nbsp; . .\out-sql.ps1 <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##&nbsp;&nbsp;&nbsp; #Export processes to table Process in database Scratch on local sql server <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##&nbsp;&nbsp;&nbsp; get-process | out-sql -SqlServer . -database Scratch -table Process -dropexisting $true<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##&nbsp;&nbsp;&nbsp; #Export volume details from 4 servers into a table<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##&nbsp;&nbsp;&nbsp; @("Server1","Server2","Server3","Server4") `<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##&nbsp;&nbsp;&nbsp; | % {$Server = $_ ; Get-WMIObject Win32_Volume -computer $Server } `<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##&nbsp;&nbsp;&nbsp; | Select-Object `<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SystemName, `<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Name, `<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @{Name="CapacityGb";Expression={[math]::truncate($_.Capacity / 1Gb)}}, `<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @{Name="FreeGb";Expression={[math]::truncate($_.FreeSpace / 1Gb)}} `<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##&nbsp;&nbsp;&nbsp; | out-sql -sqlserver . -database Scratch -table DiskVolume -dropexisting $true<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">##############################################################################<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'">function</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: cadetblue; FONT-FAMILY: 'Courier New'">Out-Sql</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">(</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$SqlServer</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$null</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">,</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$Database</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$null</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">,</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$Table</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$null</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">,</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$DropExisting</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'">$false</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">,</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$RowId</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"RowID"</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">) {<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'">begin</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp; {<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$Line</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> 0<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: teal; FONT-FAMILY: 'Courier New'">string</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">]</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$CreateTable</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">""</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'">if</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">(</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">-not</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$SqlServer</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">) { </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'">throw</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">'Out-Sql expects $SqlServer parameter'</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> }<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'">if</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">(</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">-not</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$Database</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">) { </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'">throw</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">'Out-Sql expects $Database parameter'</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> }<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'">if</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">(</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">-not</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$Table</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">) { </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'">throw</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">'Out-Sql expects $Table parameter'</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> }<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'">if</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">(</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$DropExisting</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">) { </SPAN><B><SPAN style="FONT-SIZE: 8pt; COLOR: cadetblue; FONT-FAMILY: 'Courier New'">write-debug</SPAN></B><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"Note: If the table exists, it WILL be dropped and re-created."</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$SqlConnectionString</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"&nbsp; Provider=sqloledb;"</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">+</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"&nbsp; Data Source=$SqlServer;"</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">+</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"&nbsp; Initial Catalog=$Database;"</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">+</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"&nbsp; Integrated Security=SSPI;"</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><B><SPAN style="FONT-SIZE: 8pt; COLOR: cadetblue; FONT-FAMILY: 'Courier New'">write-debug</SPAN></B><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"Will open connection to SQL server ""$SqlServer"" and will populate table ""$Table."""</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><B><SPAN style="FONT-SIZE: 8pt; COLOR: cadetblue; FONT-FAMILY: 'Courier New'">write-debug</SPAN></B><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"Connection string: `n$SqlConnectionString"</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$SqlConnection</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><B><SPAN style="FONT-SIZE: 8pt; COLOR: cadetblue; FONT-FAMILY: 'Courier New'">New-Object</SPAN></B><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">System.Data.OleDb.OleDbConnection</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$SqlConnectionString</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$SqlCommand</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><B><SPAN style="FONT-SIZE: 8pt; COLOR: cadetblue; FONT-FAMILY: 'Courier New'">New-Object</SPAN></B><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">System.Data.OleDb.OleDbCommand</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">""</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">,</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$SqlConnection</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$SqlConnection</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">.Open()<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp; }<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'">process</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp; {<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$Line</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">++</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$Properties</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: navy; FONT-FAMILY: 'Courier New'">$_</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">.PSObject.Properties<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'">if</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> (</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">-not</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$Properties</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">) <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'">throw</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"Out-Sql expects object to be passed on the pipeline. The object must have .PSObject.Properties collection."</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">#if we're at the first line, initialize the table<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'">if</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> (</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$Line</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">-eq</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> 1) <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">#initialize SQL connection and create table<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'">if</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">(</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$DropExisting</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">) { </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$CreateTable</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">+=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"IF OBJECT_ID('$Table') IS NOT NULL DROP TABLE $Table;`n"</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$CreateTable</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">+=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"CREATE TABLE $Table ( `n"</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$col</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> 0<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'">if</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> (</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$RowId</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">) <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$col</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">++</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$CreateTable</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">+=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"$RowId INT NOT NULL IDENTITY(1,1) PRIMARY KEY CLUSTERED `n"</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'">foreach</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">(</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$Property</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'">in</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$Properties</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$col</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">++</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'">if</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> (</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$col</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">-gt</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> 1) { </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$CreateTable</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">+=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">","</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> }<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'"># In below, why not use "if ($Property.Value -is [datetime])"?<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'"># Because access can be denied to the value, but Property.TypeNameOfValue would still be accessible!<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'">if</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> (</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$Property</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">.TypeNameOfValue </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">-eq</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"System.DateTime"</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">) <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$CreateTable</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">+=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"$($Property.Name) DATETIME NULL `n"</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'">else</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$CreateTable</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">+=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"$($Property.Name) NVARCHAR(MAX) NULL `n"</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$CreateTable</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">+=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">")"</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><B><SPAN style="FONT-SIZE: 8pt; COLOR: cadetblue; FONT-FAMILY: 'Courier New'">write-debug</SPAN></B><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"Will execute SQL to create table: `n$CreateTable"</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$SqlCommand</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">.CommandText </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$CreateTable</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$rows</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$SqlCommand</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">.ExecuteNonQuery()<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">#Prepare SQL insert statement and execute it<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$InsertStatement</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"INSERT $Table VALUES("</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$col</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> 0<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'">foreach</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">(</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$Property</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'">in</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$Properties</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$col</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">++</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'">if</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> (</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$col</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">-gt</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> 1) { </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$InsertStatement</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">+=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">","</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> }<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'">#In the INSERT statement, do speacial tratment for Nulls, Dates and XML. Other special cases can be added as needed.<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'">if</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> (</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">-not</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$Property</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">.Value)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$InsertStatement</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">+=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"null `n"</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'">elseif</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> (</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$Property</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">.Value </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">-is</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> [</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: teal; FONT-FAMILY: 'Courier New'">datetime</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">])<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$InsertStatement</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">+=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"'"</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">+</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$Property</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">.Value.ToString(</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"yyyy-MM-dd HH:mm:ss.fff"</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">) </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">+</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"'`n"</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'">elseif</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> (</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$Property</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">.Value </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">-is</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> [</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: teal; FONT-FAMILY: 'Courier New'">System.Xml.XmlNode</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">] </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">-or</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$Property</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">.Value </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">-is</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> [</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: teal; FONT-FAMILY: 'Courier New'">System.Xml.XmlElement</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">])<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$InsertStatement</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">+=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"'"</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">+</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> ([</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: teal; FONT-FAMILY: 'Courier New'">string</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">]$(</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$Property</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">.Value.Get_OuterXml())).Replace(</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"'"</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">,</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"''"</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">) </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">+</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"'`n"</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'">else</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$InsertStatement</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">+=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"'"</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">+</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> ([</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: teal; FONT-FAMILY: 'Courier New'">string</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">]$(</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$Property</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">.Value)).Replace(</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"'"</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">,</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"''"</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">) </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">+</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"'`n"</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$InsertStatement</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">+=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">")"</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><B><SPAN style="FONT-SIZE: 8pt; COLOR: cadetblue; FONT-FAMILY: 'Courier New'">write-debug</SPAN></B><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"Running insert statement: `n $InsertStatement"</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$SqlCommand</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">.CommandText </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$InsertStatement</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$rows</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: 'Courier New'">=</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$SqlCommand</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">.ExecuteNonQuery()<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp; }<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'">end</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp; {<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><B><SPAN style="FONT-SIZE: 8pt; COLOR: cadetblue; FONT-FAMILY: 'Courier New'">write-debug</SPAN></B><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'">"closing SQL connection..."</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: purple; FONT-FAMILY: 'Courier New'">$SqlConnection</SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">.Close()<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">&nbsp; }<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: 'Courier New'">}<o:p></o:p></SPAN></P>
<P><BR>Enjoy,<BR>Alexey</P>]]></content:encoded>
    </item>
    <item>
      <title>Optimize MERGE statement when only a “slice” of target table is affected</title>
      <link>https://docs.microsoft.com/archive/blogs/sqlthoughts/optimize-merge-statement-when-only-a-slice-of-target-table-is-affected</link>
      <pubDate>Wed, 18 Jun 2008 03:00:00 GMT</pubDate>
      <dc:creator><![CDATA[ayeltsov]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/sqlthoughts/2008/06/18/optimize-merge-statement-when-only-a-slice-of-target-table-is-affected/</guid>
      <description><![CDATA[Note: This post assumes reader is familiar with SQL Server 2008 MERGE statement (refresher).
In...]]></description>
      <content:encoded><![CDATA[<P mce_keep="true">Note: This post assumes reader is familiar with SQL Server 2008 MERGE statement (<A href="https://technet.microsoft.com/en-us/library/bb510625(SQL.100).aspx" target=_blank mce_href="https://technet.microsoft.com/en-us/library/bb510625(SQL.100).aspx">refresher</A>).</P>
<P>In recent months I had a few chances to use MERGE statement, and I realized that frequently input data applies only to a “slice”&nbsp;or "window"&nbsp;(could say “partition”, but let’s not reuse that term) of the target table. Let me illustrate on example.</P>
<P>Suppose database tracks occupancy of offices in a campus with multiple buildings. Suppose that updates always come in per-building batches. Below shows how to handle such cases in optimal way.</P>
<P>Let’s define our table structure and get some sample data:</P>
<BLOCKQUOTE>
<P>--USE &lt;YourDatabase&gt;<BR>DROP TABLE BuildingOccupancy<BR>DROP TABLE ImportBuildingData<BR>GO 
<P>-- Define tables 
<P>-- This is our target table<BR>CREATE TABLE BuildingOccupancy(BuildingId int, OfficeNumber int, OccupiedBy int, <BR>&nbsp;&nbsp;&nbsp;&nbsp; CONSTRAINT BuildingOccupancy_PK PRIMARY KEY(BuildingId, OfficeNumber)); 
<P>-- This is our source data.<BR>-- Note that it does not have BuildingId because business rules dictate that import is done per-building<BR>-- The corresponding BuildingId to be imported will come from a variable<BR>CREATE TABLE ImportBuildingData(OfficeNumber int, OccupiedBy int, <BR>&nbsp;&nbsp;&nbsp;&nbsp; CONSTRAINT ImportBuildingData_PK PRIMARY KEY(OfficeNumber)); 
<P>-- Populate tables with mock-up data 
<P>-- Create target table's data.<BR>-- Say we have 40 buildings, each with 5 floors and 200 offices on each floor.<BR>-- That is 40K rows<BR>INSERT BuildingOccupancy(BuildingId,OfficeNumber,OccupiedBy)<BR>SELECT Building.BuildingID,Office.OfficeNumber, OccupiedBy = ROW_NUMBER() OVER (ORDER BY Office.OfficeNumber,Building.BuildingID)<BR>FROM <BR>&nbsp; (<BR>&nbsp;&nbsp;&nbsp; -- this just returns numbers 1..40<BR>&nbsp;&nbsp;&nbsp; SELECT TOP 40 BuildingID = ROW_NUMBER() OVER (ORDER BY object_id) FROM msdb.sys.objects<BR>&nbsp; ) AS Building<BR>&nbsp; CROSS JOIN<BR>&nbsp; (<BR>&nbsp;&nbsp;&nbsp; -- this just returns numbers 1..1000<BR>&nbsp;&nbsp;&nbsp; SELECT TOP 1000 OfficeNumber = ROW_NUMBER() OVER (ORDER BY object_id) FROM msdb.sys.objects<BR>&nbsp; ) AS Office 
<P>-- Create some import data.<BR>-- Suppose the new building data is 90% unchanged, the rest 10% are split between <BR>-- 5% deletes (people "moved out" of the offices) and 5% updates (someone else moved into the office)<BR>-- Let's say import data happens to be about building 12 
<P>INSERT ImportBuildingData(OfficeNumber, OccupiedBy)<BR>SELECT OfficeNumber, OccupiedBy<BR>FROM BuildingOccupancy WHERE BuildingId = 12 
<P>-- Delete 5% of the data<BR>DELETE ImportBuildingData <BR>WHERE OfficeNumber % 20 = 1 
<P>-- Update 5% of the data<BR>UPDATE ImportBuildingData <BR>SET OccupiedBy = OccupiedBy+30000<BR>WHERE OfficeNumber % 20 = 5</P></BLOCKQUOTE>
<P>Now, let’s import the data using the MERGE statement. We’ll compare two approaches which produce same result:</P>
<BLOCKQUOTE>
<P>-- Approach 1: 
<P>DECLARE @InputBuilding INT = 12; 
<P>MERGE BuildingOccupancy AS t<BR>&nbsp; USING ImportBuildingData AS s<BR>&nbsp; ON t.OfficeNumber = s.OfficeNumber AND t.BuildingId = @InputBuilding<BR>WHEN MATCHED AND t.OccupiedBy &lt;&gt; s.OccupiedBy THEN <BR>&nbsp; UPDATE SET OccupiedBy = s.OccupiedBy<BR>WHEN NOT MATCHED BY TARGET THEN<BR>&nbsp; INSERT VALUES(@InputBuilding, OfficeNumber, OccupiedBy)<BR>WHEN NOT MATCHED BY SOURCE AND t.BuildingId = @InputBuilding THEN<BR>&nbsp; DELETE; 
<P>-- Approach 2:</P>
<P>DECLARE @InputBuilding INT = 12; <BR><BR>;WITH FilteredBuilding AS (<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SELECT *<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FROM BuildingOccupancy<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WHERE BuildingId = @InputBuilding<BR>)<BR>MERGE FilteredBuilding AS t<BR>&nbsp; USING ImportBuildingData AS s<BR>&nbsp; ON t.OfficeNumber = s.OfficeNumber AND t.BuildingId = @InputBuilding<BR>WHEN MATCHED AND t.OccupiedBy &lt;&gt; s.OccupiedBy THEN <BR>&nbsp; UPDATE SET OccupiedBy = s.OccupiedBy<BR>WHEN NOT MATCHED BY TARGET THEN<BR>&nbsp; INSERT VALUES(@InputBuilding, OfficeNumber, OccupiedBy)<BR>WHEN NOT MATCHED BY SOURCE THEN<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DELETE;</P></BLOCKQUOTE>
<P>Approach 1 uses AND t.BuildingId = @InputBuilding in the delete section to make sure we don’t delete data that belongs to other buildings.<BR>Approach 2 uses CTE (Common Table Expression – <A href="https://technet.microsoft.com/en-us/library/ms175972(SQL.100).aspx" target=_blank mce_href="https://technet.microsoft.com/en-us/library/ms175972(SQL.100).aspx">refresher</A>) to restrict MERGE operation to only building of interest. Note that there’s no longer need for additional condition in the delete section.</P>
<P>While both approaches achieve same result, performance is quite different. Approach 1 does 500+ reads and Approach 2 does less than 10. This is because the whole target table (BuildingOccupancy) is scanned in the first approach, and in the second approach index seek is used (please feel free to inspect this in the query plan).</P>
<P>You may have noted that approach 2 is using a redundant AND condition in the join (e.g. why did I add AND t.BuildingId = @InputBuilding if it’s already filtered out in the CTE). This is actually needed to help optimizer a bit. If we were to use literal value, the additional clause would not be necessary. SQL team might optimize this in the next version, but adding this extra clause does not hurt.</P>
<P>MERGE also allows use of view or TVF as a source, but I believe using CTE is most readable choice.</P>
<P>Acknowledgements: Thanks to Sara Tahir for&nbsp;the CTE trick and to Andrew Richardson for explaing&nbsp;the need of redundant join clause.</P>
<P>P.S. If you have SQL Server 2008 older than RC0, above MERGE statements will fail with syntax error. There was a slight wording change in merge clauses between CTP6 and RC:</P>
<P><SPAN style="mso-bidi-font-family: 'Times New Roman'; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin; mso-bidi-theme-font: minor-bidi"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p><FONT face=Calibri size=3>
<TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1" cellSpacing=0 cellPadding=0 border=1 class="MsoTableGrid">
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes">
<TD class="" style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: black 1pt solid; WIDTH: 239.25pt; PADDING-TOP: 0in; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid black .5pt; mso-border-themecolor: text1" vAlign=top width=319>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face=Calibri><STRONG>Old Syntax:<o:p></o:p></STRONG></FONT></FONT></P></TD>
<TD class="" style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: #f0f0f0; WIDTH: 239.25pt; PADDING-TOP: 0in; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1" vAlign=top width=319>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face=Calibri><STRONG>New Syntax (RC0 and all subsequent releases):<o:p></o:p></STRONG></FONT></FONT></P></TD></TR>
<TR style="mso-yfti-irow: 1">
<TD class="" style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #f0f0f0; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: black 1pt solid; WIDTH: 239.25pt; PADDING-TOP: 0in; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1" vAlign=top width=319>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face=Calibri>WHEN TARGET NOT MATCHED<o:p></o:p></FONT></FONT></P></TD>
<TD class="" style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #f0f0f0; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: #f0f0f0; WIDTH: 239.25pt; PADDING-TOP: 0in; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=319>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face=Calibri>WHEN NOT MATCHED BY TARGET<o:p></o:p></FONT></FONT></P></TD></TR>
<TR style="mso-yfti-irow: 2; mso-yfti-lastrow: yes">
<TD class="" style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #f0f0f0; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: black 1pt solid; WIDTH: 239.25pt; PADDING-TOP: 0in; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1" vAlign=top width=319>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face=Calibri>WHEN SOURCE NOT MATCHED<o:p></o:p></FONT></FONT></P></TD>
<TD class="" style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #f0f0f0; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: #f0f0f0; WIDTH: 239.25pt; PADDING-TOP: 0in; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=319>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face=Calibri>WHEN NOT MATCHED BY SOURCE<o:p></o:p></FONT></FONT></P></TD></TR></TBODY></TABLE></FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Times New Roman'; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin; mso-bidi-theme-font: minor-bidi"><o:p><FONT face=Calibri size=3>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><A class="" title=_MailAutoSig name=_MailAutoSig></A><o:p><FONT face=Calibri size=3>&nbsp;</FONT></o:p></P>
<P mce_keep="true">&nbsp;</P>]]></content:encoded>
    </item>
    <item>
      <title>Why should you install SQL 2008 from the command line</title>
      <link>https://docs.microsoft.com/archive/blogs/sqlthoughts/why-should-you-install-sql-2008-from-the-command-line</link>
      <pubDate>Tue, 17 Jun 2008 12:56:00 GMT</pubDate>
      <dc:creator><![CDATA[ayeltsov]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/sqlthoughts/2008/06/17/why-should-you-install-sql-2008-from-the-command-line/</guid>
      <description><![CDATA[&nbsp;&nbsp;If a project needs several SQL Servers, I believe that command-line setup is the way to...]]></description>
      <content:encoded><![CDATA[<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p><FONT face=Calibri size=3>&nbsp;</FONT></o:p><o:p><FONT face=Calibri size=3>&nbsp;</FONT></o:p><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'">If a project needs several SQL Servers, I believe that command-line setup is the way to install SQL Server for the following reasons:<o:p></o:p></SPAN></P>
<UL type=disc>
<LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l0 level1 lfo1; tab-stops: list .5in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'">Speed. Once the process is established, it's quick to follow.<o:p></o:p></SPAN></LI>
<LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l0 level1 lfo1; tab-stops: list .5in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'">Lesser chance of making mistake while navigating the setup GUI.<o:p></o:p></SPAN></LI>
<LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l0 level1 lfo1; tab-stops: list .5in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'">Guarantees that instances in your project are installed exactly the same way.<o:p></o:p></SPAN></LI>
<LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l0 level1 lfo1; tab-stops: list .5in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'">If setup runs into problems, it's very easy to escalate, because you know exactly what you&nbsp;did<o:p></o:p></SPAN></LI></UL>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'">This is how typical SQL command-line setup command looks like:</SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'"><o:p></o:p></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><SPAN style="FONT-SIZE: 10pt; COLOR: #0070c0; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Times New Roman'">setup.exe /q /PID="XXXXX-XXXXX-XXXXX-XXXXX-XXXXX" /ACTION=install /FEATURES=SQL,IS,Tools,BIDS /InstanceName=MSSQLSERVER /SQLSVCACCOUNT="DOMAIN\svcaccount" /AGTSVCACCOUNT="DOMAIN\svcaccount" /SQLSYSADMINACCOUNTS="BUILTIN\ADMINISTRATORS" /ISSVCAccount="NT AUTHORITY\Network Service" /AGTSVCSTARTUPTYPE=2 /SQLSVCSTARTUPTYPE=2/ISSVCSTARTUPTYPE=2 /InstanceDir=D:\ /ERRORREPORTING=1 /SQMREPORTING=1 /SQLSVCPASSWORD="****" /AGTSVCPASSWORD="****" /SQLSYSADMINACCOUNTS="BUILTIN\ADMINISTRATORS" "DOMAIN\svcaccount"<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'">A few comments:<o:p></o:p></SPAN></P>
<UL type=disc>
<LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l1 level1 lfo2; tab-stops: list .5in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'">The complete syntax and all the options can be found in Books Online (<A class="" title="How to: Install SQL Server 2008 from the Command Prompt" href="https://msdn.microsoft.com/en-us/library/ms144259(SQL.100).aspx" mce_href="https://msdn.microsoft.com/en-us/library/ms144259(SQL.100).aspx">How to: Install SQL Server 2008 from the Command Prompt</A>)</SPAN></LI>
<LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l1 level1 lfo2; tab-stops: list .5in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'">The edition is inferred from the /PID. If /PID is not specified, evaluation edition (180-day expiration) is installed.<o:p></o:p></SPAN></LI>
<LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l1 level1 lfo2; tab-stops: list .5in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'">There are some pre-requisites to SQL Setup (Windows Installer 4.5, Powershell). If they are not installed, the setup will install them first and may ask you to reboot and re-run the setup.<o:p></o:p></SPAN></LI>
<LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l1 level1 lfo2; tab-stops: list .5in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'">At least with SQL Server 2008 RC With Vista/Win2008 it's better to run the setup from elevated (Administrator) command prompt. If ran from non-elevated command prompt, the setup will not be able to print errors or messages - it will just silently end, and you will have to look at the setup logs to see what happened.<o:p></o:p></SPAN></LI>
<LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l1 level1 lfo2; tab-stops: list .5in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'">Even with successful setup, the logs should be inspected. The summary log is here: "C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log\Summary.txt". On successful install, there's a "Final result:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Passed" line at the top of the log.<o:p></o:p></SPAN></LI>
<LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l1 level1 lfo2; tab-stops: list .5in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'">For couple of reasons, I don't like SQL installed into C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\... - I prefer that SQL is installed in the root of a different drive.&nbsp;Hence I specified /InstanceDir=D:\ (SQL will be installed into D:\MSSQL10.MSSQLSERVER\MSSQL), but if you like default just don't specify this parameter.<o:p></o:p></SPAN></LI></UL>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'">Now, the fresh install of SQL will not allow connections from outside. Continuing command-line theme, here is how one can enable Named Pipes and TCP/IP&nbsp;(SQL needs to be cycled for changes to take effect):<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'"><o:p></o:p></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><SPAN style="FONT-SIZE: 10pt; COLOR: #0070c0; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Times New Roman'">WMIC /NAMESPACE:\\root\Microsoft\SqlServer\ComputerManagement10 PATH ServerNetworkProtocol WHERE "ProtocolName='Tcp' OR ProtocolName='Np'" CALL SetEnable<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'">Open up port 1433 for TCP/IP connections:<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><SPAN style="FONT-SIZE: 10pt; COLOR: #0070c0; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Times New Roman'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><SPAN style="FONT-SIZE: 10pt; COLOR: #0070c0; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Times New Roman'">netsh firewall add portopening TCP 1433 SQLServerDefaultInstance<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'">You will need to tweak these commands for your environment, but I'm sure that small investment into getting your command-line install steps documented will speed up your installs and bring better predictability. </SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'">As a DBA, I found especially useful to provide a guide to Developers and Testers for the SQL setups. Now when I log into their server to troubleshoot something, I know how exactly SQL was installed.<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face=Calibri size=3>&nbsp;</FONT></o:p></P>]]></content:encoded>
    </item>
  </channel>
</rss>