Solved

is this the correct syntax for my sql/php statement

Posted on 2008-10-01
10
150 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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

758 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

21 Experts available now in Live!

Get 1:1 Help Now