Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

is this the correct syntax for my sql/php statement

Posted on 2008-10-01
10
Medium Priority
?
160 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
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
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.
Suggested Courses

916 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