Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

is this the correct syntax for my sql/php statement

Posted on 2008-10-01
10
Medium Priority
?
159 Views
Last Modified: 2013-12-12
i have a table that will have a lot of empty fields that i want to exclude from my query.

is this the correct syntax

$sql .= " Select * FROM REQUEST WHERE R_STATUS = 'S' and R_GTM_LAUNCH='No'  and (!isnull(R_GTM_LAUNCH) ORDER BY R_NUMBER DESC";
0
Comment
Question by:justmelat
[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
  • 5
  • 5
10 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 22614895
when R_GTM_LAUNCH equals 'No', then it cannot be null, So you do not need the null condition:
$sql .= " Select * FROM `REQUEST` WHERE `R_STATUS` = 'S' and `R_GTM_LAUNCH`='No'   ORDER BY R_NUMBER DESC";
0
 
LVL 82

Expert Comment

by:hielo
ID: 22614934
>>a lot of empty fields
If you are trying to avoid the fields that you will get from the *, then you need to check each field individually via (fieldname IS NOT NULL):
$sql .= " Select * FROM REQUEST WHERE R_STATUS = 'S' and R_GTM_LAUNCH='No'  and (`field1` IS NOT NULL)  and (`field2` IS NOT NULL) ORDER BY


0
 
LVL 1

Author Comment

by:justmelat
ID: 22615087
Hielo

we are change the db, so now the launch field will always have a value, before it was sometimes empty/null, so in my query I want it to ignore the time when launch is empty.
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 82

Expert Comment

by:hielo
ID: 22615108
$sql .= " Select * FROM REQUEST WHERE R_STATUS = 'S' and (R_GTM_LAUNCH IS NOT NULL)
0
 
LVL 1

Author Comment

by:justmelat
ID: 22615464
Hielo,

it's still grabbing the empty fields.  Is !empty and option?
0
 
LVL 82

Expert Comment

by:hielo
ID: 22615519
>> Is !empty and option?
No. there is no such function in MySQL.

You probably have some fields set to an empty string, and others set to NULL. Try:
$sql .= " Select * FROM REQUEST WHERE R_STATUS = 'S' and (''<>R_GTM_LAUNCH) AND (R_GTM_LAUNCH IS NOT NULL)
0
 
LVL 1

Author Comment

by:justmelat
ID: 22615923
I just realized what you were saying at first the null values shouldn't appear any way because they don't equal no

i have to be doing something else wrongl.
0
 
LVL 1

Author Comment

by:justmelat
ID: 22615944
did you mean to have the "<>?  I've never seend that used in a query like this

(''<>R_GTM_LAUNCH)
0
 
LVL 82

Accepted Solution

by:
hielo earned 1600 total points
ID: 22616241
>>did you mean to have the "<>?
Yes, the is the "NOT EQUAL" operator. You can also use:
('' != R_GTM_LAUNCH)
0
 
LVL 1

Author Comment

by:justmelat
ID: 22645585
That's Hielo, you rock!  as always.  Thanks.
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

721 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