Solved

is this the correct syntax for my sql/php statement

Posted on 2008-10-01
10
151 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
  • 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
 
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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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 400 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
count download link and run update query 9 54
Easy to use inventory management software 7 66
php date - compare 4 40
mysqli 3 18
This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

932 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now