Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Test a null value in SQL Row

Posted on 2014-04-02
6
Medium Priority
?
353 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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonstā€¦
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ā€¦

618 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