Link to home
Start Free TrialLog in
Avatar of justmelat
justmelat

asked on

is this the correct syntax for my sql/php statement

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";
Avatar of hielo
hielo
Flag of Wallis and Futuna image

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


Avatar of justmelat
justmelat

ASKER

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.
$sql .= " Select * FROM REQUEST WHERE R_STATUS = 'S' and (R_GTM_LAUNCH IS NOT NULL)
Hielo,

it's still grabbing the empty fields.  Is !empty and option?
>> 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)
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.
did you mean to have the "<>?  I've never seend that used in a query like this

(''<>R_GTM_LAUNCH)
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That's Hielo, you rock!  as always.  Thanks.