--- Chris <[EMAIL PROTECTED]> wrote:

> I want to create a SELECT statement using BETWEEN like:
> SELECT * FROM mytable WHERE myfield BETWEEN value_1 AND value_2.  The
> field 
> I'm applying my BETWEEN clause is a varchar.
> 
> Now, if value_1 and value_2 are numbers the select statement works as
> is. If 
> value_1 and value_2 are characters I need to enclose them with
> apostrophes 
> like: SELECT * FROM mytable WHERE myfield BETWEEN 'value_1' AND
> 'value_2'.
> 
> If the appropriate format (enclosing or not enclosing with
> apostrophes) is 
> not followed the query fails.
> 
> Is there a way to generalize my SELECT statement so value_1 and
> value_2 can 
> be numbers or characters?
> 
> Thanks
> cw 
> 

Whether you compare against string literals or numeric literals (quotes
or no quotes) depends on the data type of the field `myfield`.  Strings
will be automagically converted to numbers if necessary but that's a
performance killer if you have to run this query frequently.

Basically, the answer is "no" because what you are comparing it against
may not be both numeric AND text a the same time. Practically, if you
quote your numbers, the autoconversion should kick in and you should be
comparing numbers to numbers again.

Please read for more details:
http://dev.mysql.com/doc/refman/5.0/en/string-syntax.html
http://dev.mysql.com/doc/refman/5.0/en/number-syntax.html

Shawn Green

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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

Reply via email to