Solved

is this the correct syntax for my sql/php statement

Posted on 2008-10-01
10
155 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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
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 count occurrences of each item in an array.

734 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