Jump to content

MySQL operators


molemenacer

Recommended Posts

I have a query that works all apart from the last line, i show the query first:

[code]
where
jobs.statusid in (6) and
ifnull(jobs.currworkerid,'') like '%' and
jobs.dictatorid like '%' and
jobs.custcode like '%' and
jobs.deptcode like '%' and
jobs.specialitycode like '%' and
ifnull(jobs.prevworkerid,'') like '%' and
jobs.jobid like '%' and
jobs.supplierid like '%' and
Approveddate between '2006-09-14' and '2006-09-21' or Approveddate Is Null
[/code]

The where clause all works apart from the approveddate.  When this runs it finds uses the criteria apart from approveddate is null and that returns every record that has a null entry in the approveddate field.  It ignores that status = 6.

i need a way of having approveddate part of the whole where clause and it looks for status=6 with approveddate = null.

Any help would be gratefully recieved

Thanks
Link to comment
Share on other sites

by default, mysql is basically interpreting your clause like this:
[code]
where
(jobs.statusid in (6) and
ifnull(jobs.currworkerid,'') like '%' and
jobs.dictatorid like '%' and
jobs.custcode like '%' and
jobs.deptcode like '%' and
jobs.specialitycode like '%' and
ifnull(jobs.prevworkerid,'') like '%' and
jobs.jobid like '%' and
jobs.supplierid like '%' and
Approveddate between '2006-09-14' and '2006-09-21') or (Approveddate Is Null)
[/code]

you need to place parenthesis around the areas you want grouped like so:
[code]
where
jobs.statusid in (6) and
ifnull(jobs.currworkerid,'') like '%' and
jobs.dictatorid like '%' and
jobs.custcode like '%' and
jobs.deptcode like '%' and
jobs.specialitycode like '%' and
ifnull(jobs.prevworkerid,'') like '%' and
jobs.jobid like '%' and
jobs.supplierid like '%' and
(Approveddate between '2006-09-14' and '2006-09-21' or Approveddate Is Null)
[/code]
Link to comment
Share on other sites

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.