Jump to content

Recommended Posts

I have the following query:

  SELECT COUNT(fldVolunteerID)
  FROM tbl_volunteer
  WHERE fldDateDenied IS NOT NULL
  AND UNIX_TIMESTAMP(fldDateDenied) > UNIX_TIMESTAMP(fldDateApproved)
  AND fldDenyFlag = 1

and it is not returning the desired output. Problem is that both fldDateDenied and fldDateApproved potentially could be NULL, and I think that is stuffing up my query.

What will the effect be of converting a NULL value to UNIX_TIMSTAMP, and then performing a comparison? In the above example: what if fldDateApproved = NULL ?

Currently, the query results in a COUNT of 0 (zero), which is not correct (there should be results).

All help much appreciated.
Link to comment
https://forums.phpfreaks.com/topic/16908-datetime-comparison-and-null-values/
Share on other sites

Duh! ORs... After rereading your post this morning, I finally got it. Must have been very tired. Was thinking it was an acronym of sorts.

Anyways, 30 secs after reading your reply I got it working:

SELECT COUNT(fldVolunteerID)
FROM tbl_volunteer
WHERE fldDateDenied IS NOT NULL
AND fldDateApproved IS NOT NULL
AND fldDateDenied > fldDateApproved
AND fldDenyFlag = 1
OR  fldDateDenied IS NOT NULL
AND fldDateApproved IS NULL
AND fldDenyFlag = 1

Thanks heaps fenway. Much obliged.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.