[SOLVED] Using STRCMP in a query

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

[SOLVED] Using STRCMP in a query

Post 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?
Last edited by Bill H on Wed Feb 07, 2007 2:21 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Your STRCMP() call is comparing two strings.
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post 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?
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Post 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.
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post 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.
Post Reply