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

<channel>
	<title>PowerShell Station &#187; SQL Server</title>
	<atom:link href="http://powershellstation.com/tag/sql-server/feed/" rel="self" type="application/rss+xml" />
	<link>http://powershellstation.com</link>
	<description>Mike&#039;s PowerShell Musings</description>
	<lastBuildDate>Wed, 14 Dec 2011 04:37:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Checking a Field for NULL in PowerShell</title>
		<link>http://powershellstation.com/2010/04/09/checking-a-field-for-null-in-powershell/</link>
		<comments>http://powershellstation.com/2010/04/09/checking-a-field-for-null-in-powershell/#comments</comments>
		<pubDate>Sat, 10 Apr 2010 03:45:30 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[NULL]]></category>
		<category><![CDATA[Script]]></category>

		<guid isPermaLink="false">http://powershellstation.com/2010/04/09/checking-a-field-for-null-in-powershell/</guid>
		<description><![CDATA[It’s been a long time (over 2 months) since I last posted.  I’ll try to get back into a rhythm of posting at least weekly.  Anyway, this is something that occurred to me at work when writing a script. I usually avoid nullable columns, but sometimes date fields make sense to be null (rather than [...]]]></description>
			<content:encoded><![CDATA[<p>It’s been a long time (over 2 months) since I last posted.  I’ll try to get back into a rhythm of posting at least weekly.  Anyway, this is something that occurred to me at work when writing a script.</p>
<p>I usually avoid nullable columns, but sometimes date fields make sense to be null (rather than use sentinel values like 1/1/1900).  In this case, I had a nullable date column and I needed to check in PowerShell whether the field was in fact null or not.  In SQL, I would have just used an IS NULL, or used the IsNull() function to replace the null value with something a little easier to deal with.  My first (feeble) attempt was to do this:</p>
<pre class="brush:powershell">if (!$_.completedDate){
# it’s null
}</pre>
<p>Unfortunately for me, that doesn’t work.  Next, I used this (which worked, but wasn’t very satisfactory either):</p>
<pre class="brush:powershell">if ($_.completedDate.ToString() -eq ''){
# it’s null
}</pre>
<p>Realizing that I was being stupid, I googled “PowerShell SQL NULL and after looking at several pages which didn’t really address the issue, I found <a href="http://blogs.technet.com/industry_insiders/pages/testing-for-database-null-values-from-powershell.aspx">this.</a> A little work to change it into a function, and voilà.</p>
<pre class="brush:powershell">function is-null($value){
  return  [System.DBNull]::Value.Equals($value)
}</pre>
<p>A few quick tests and this is what I wanted. Now, my code looks like this:</p>
<pre class="brush:powershell">if (is-null $_.completedDate){
# it’s null
}</pre>
<p>I find it hard to believe I haven’t written this function before (or seen it).</p>
<p>By the way…be watching the <a href="http://sqlpsx.codeplex.com">SQL PowerShell Extensions</a> project.  Chad released version 2.1, which includes SQL mode for the ISE (really nice).  I know he and several others are collaborating on an update which should be out sometime soon.</p>
<p>-Mike</p>
]]></content:encoded>
			<wfw:commentRss>http://powershellstation.com/2010/04/09/checking-a-field-for-null-in-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL PowerShell Extensions (SQLPSX) 2.0 Released</title>
		<link>http://powershellstation.com/2010/01/05/sql-powershell-extensions-sqlpsx-2-0-released/</link>
		<comments>http://powershellstation.com/2010/01/05/sql-powershell-extensions-sqlpsx-2-0-released/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 00:39:17 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Script]]></category>

		<guid isPermaLink="false">http://powershellstation.com/?p=233</guid>
		<description><![CDATA[The first module-based release of the SQL PowerShell Extensions (SQLPSX) was released recently on CodePlex.  It features very handy wrappers for most of the SMO objects used to manipulate SQL Server metadata, SSIS packages, Replication, and (new in the 2.0 release) an ADO.NET module which I wrote based on the code in this post.  There&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>The first module-based release of the SQL PowerShell Extensions (SQLPSX) was released recently on CodePlex.  It features very handy wrappers for most of the SMO objects used to manipulate SQL Server metadata, SSIS packages, Replication, and (new in the 2.0 release) an ADO.NET module which I wrote based on the code in this <a href="http://powershellstation.com/2009/09/15/executing-sql-the-right-way-in-powershell/">post</a>.  There&#8217;s also a data-collection process and Reporting Services reports to help you get your SQL Server installations under control.</p>
<p>Chad Miller, the driving force behind SQLPSX, has put a lot of effort into this release, and you&#8217;ll find really good examples of advanced functions (with comment-based help, even).</p>
<p>If you deal with SQL Server in any way, you&#8217;ll almost certainly be able to use this set of modules to streamline your scripting experience (and probably learn something about SMO in the process).</p>
<p>You can find the release <a href="http://sqlpsx.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=38047">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://powershellstation.com/2010/01/05/sql-powershell-extensions-sqlpsx-2-0-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  powershellstation.com/tag/sql-server/feed/ ) in 0.16479 seconds, on Feb 5th, 2012 at 10:04 pm UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 6th, 2012 at 10:04 pm UTC -->
