Solved

Test a null value in SQL Row

Posted on 2014-04-02
6
281 Views
Last Modified: 2014-04-07
Hello,

I'd like to test in a sql query if a row is null (value validated in my sql browser)

I've tested

if (! $row[0]) -> always false
if ($row[0] -eq $null) -> always false

Thx for help.
0
Comment
Question by:Sybux
  • 2
  • 2
6 Comments
 
LVL 18

Expert Comment

by:Raheman M. Abdul
Comment Utility
try this:

if(    $row[0].count -eq 0      )


or

$row -eq $null

or

$result.hasrows -eq $false
0
 
LVL 34

Expert Comment

by:Dan Craciun
Comment Utility
If !$row[0] is always false, this means $row[0] is never null.

Test to see what is stored in $row[0].
0
 

Accepted Solution

by:
Sybux earned 0 total points
Comment Utility
Finally after googled again and more, I've found the solution in this article :

http://blogs.technet.com/b/industry_insiders/archive/2008/09/15/testing-for-database-null-values-from-powershell.aspx

Basicaly, you need to test with the [System.DBNull] object like this :

if ([System.DBNull]::Value.Equals($rows[0])) { value is null } else { value is filled }
0
 
LVL 34

Expert Comment

by:Dan Craciun
Comment Utility
You're right.

For completion sake:
- null means the absence of a reference to an object
- DBNull means a nonexistent database column
0
 

Author Closing Comment

by:Sybux
Comment Utility
Google is finally still best friend but after hours of search :)
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now