zzapper wrote:

On Wed, 13 Jul 2005 00:34:15 -0400,  wrote:

Scott Haneda wrote:

I can not get this to work how I would think it should be formatted:
SELECT IF(NOW() BETWEEN sale_start AND sale_end, 'yes', 'no')
That seems to work just fine

It should, as that is correct syntax, as documented in the manual <http://dev.mysql.com/doc/mysql/en/comparison-operators.html>.

However, I was under the impression that BETWEEN was to be formatted
BETWEEN(va1, v2)

Where did you get that idea?

Which leads me to:
SELECT IF(NOW() BETWEEN(sale_start AND sale_end), 'yes', 'no')
Which gives me an error of:
You have an error in your SQL syntax. Check the manual that corresponds to
your MySQL server version for the right syntax to use near ' 'yes', 'no')
FROM products WHERE id = "75"

This is invalid syntax, hence the error message. Mysql expects "BETWEEN min_value AND max_value". Your parentheses mean that min_value is the result of (sale_start AND sale_end), which will be 0 (false) if either sale_start or sale_end is 0, otherwise it will be 1 (true). Then you are missing the 'AND max_value' part.

Michael

Could we have the corrected sql here pls?

The correct syntax was already in the 1st paragraph of the original message, as I pointed out in my reply. The correct syntax is also clearly documented in the manual page I referenced. Beyond that, what, precisely, do you want?

I guess

SELECT  IF(NOW()) BETWEEN sale_start AND sale_end,'no','yes')
                  ^ one too many parentheses.

another example

SELECT IF(STRCMP('test','test1'),'no','yes');
        -> 'no'

Michael


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to