Page 1 of 1

[SOLVED] Using STRCMP in a query

Posted: Wed Feb 07, 2007 10:40 am
by Bill H
I am using the following query, MySQL 4.1.10:

Code: Select all

SELECT * FROM Tickets WHERE idTech=4 AND (AptDate='2007-02-07' OR (JobStat=0 AND STRCMP('AptDate','2007-02-07')<0)) ORDER BY AptDate,AptTime
AptDate is a "date" field (not date-time), JobStat is a tinyint.
The query returns records with AptDate of 2007-02-07 regardless of value of JobStat.
There is a record, however, with a AptDate of 2007-02-06 and a JobStat=0 that this query is not returning.

What am I doing wrong?

Posted: Wed Feb 07, 2007 1:16 pm
by feyd
Your STRCMP() call is comparing two strings.

Posted: Wed Feb 07, 2007 2:10 pm
by Bill H
So,

Code: Select all

SELECT * FROM Tickets WHERE idTech=4 AND (AptDate='2007-02-07' OR (JobStat=0 AND AptDate<'2007-02-07')) ORDER BY AptDate,AptTime
would be correct?

Posted: Wed Feb 07, 2007 2:21 pm
by Mordred
Bill H wrote:So,

Code: Select all

SELECT * FROM Tickets WHERE idTech=4 AND (AptDate='2007-02-07' OR (JobStat=0 AND AptDate<'2007-02-07')) ORDER BY AptDate,AptTime
would be correct?
Noone will know until you try it.

Posted: Wed Feb 07, 2007 2:26 pm
by Bill H
Noone will know until you try it.
..which I was in the process of doing, and was returning to edit my posts:
the first to mark the title [SOLVED]
and the second to say that having tried it, I find it is, indeed, correct.

Thanks for the help. As always, heroes abound on phpdn.