Solved

Test a null value in SQL Row

Posted on 2014-04-02
6
307 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 19

Expert Comment

by:Raheman M. Abdul
ID: 39972545
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
ID: 39972555
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
ID: 39972655
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
ID: 39972723
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
ID: 39982593
Google is finally still best friend but after hours of search :)
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
A brief introduction to what I consider to be the best editor for PowerShell.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

789 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