?
Solved

Test a null value in SQL Row

Posted on 2014-04-02
6
Medium Priority
?
337 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 35

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 35

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

752 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