Bruce Gust
asked on
Why does this query not work for NULL?
I have a recordset that looks like this in SQL Server Studio:
defaultname overridename
Chief Financial Officer
Group Vice President
Regional Vice President
Area Vice President NULL
Chief Financial Officer NULL
Vice President NULL
Manager NULL
As I'm looping through my results, I'm trying to check to see if the overridename column is NULL. I don't care if it's empty, I want to know if it's NULL.
if($workqueueexclusiverole list[$i][" overridena me"]==NULL )
{
echo $workqueueexclusiverolelis t[$i]["def aultname"] ." | corp (unassigned)";
}
The result that I get from the above gives me every row without a value as opposed to only those that are NULL.
What am I doing wrong? How can I better craft my query so I'm getting only those rows that are NULL as opposed to everything that's empty?
defaultname overridename
Chief Financial Officer
Group Vice President
Regional Vice President
Area Vice President NULL
Chief Financial Officer NULL
Vice President NULL
Manager NULL
As I'm looping through my results, I'm trying to check to see if the overridename column is NULL. I don't care if it's empty, I want to know if it's NULL.
if($workqueueexclusiverole
{
echo $workqueueexclusiverolelis
}
The result that I get from the above gives me every row without a value as opposed to only those that are NULL.
What am I doing wrong? How can I better craft my query so I'm getting only those rows that are NULL as opposed to everything that's empty?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I would be glad to experiment with it a little bit. Can you please give us the SSCCE? That would be a pair of CREATE TABLE statements, a few queries to load the tables and a query representative of the LEFT JOIN. If you use CREATE TEMPORARY TABLE you can put all of these into a single script that we can run and rerun to tinker with the settings and displays of data.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Folks, thanks so much for your input. Here's what I did:
Once it became obvious that PHP and SQL weren't going to be talking to one another like I had hoped, I chose to simply run another query at that point I was needing the info and checked for an id value as opposed to a NULL value. It required a little more in the way of heavy lifting, but the end result was credible information exactly where I needed it and, like a great man used to say, "You can't argue with success."
Thanks so much!
Once it became obvious that PHP and SQL weren't going to be talking to one another like I had hoped, I chose to simply run another query at that point I was needing the info and checked for an id value as opposed to a NULL value. It required a little more in the way of heavy lifting, but the end result was credible information exactly where I needed it and, like a great man used to say, "You can't argue with success."
Thanks so much!
Thanks for the points and thanks for using EE, ~Ray
ASKER
Ray, here's my dilemma: The recordset that I'm using is a result of a LEFT JOIN query. The NULL values are representative of a row in one of the tables that doesn't exist as opposed to a situation where I had a legitimate row with a NULL column. That being the case, changing the default value wouldn't make a dent, would it? Reason being is that the NULL value displays to indicate a record in one table that doesn't exist in the other.
My logic may be off, but if what I'm saying resonates with you, what then are my options if I can't change the default value of my column?