List:General Discussion« Previous MessageNext Message »
From:Steve Musumeche Date:September 28 2006 8:05pm
Subject:Re: making varchar field to act like numeric field
View as plain text  
Dan,

Thank you, that works!  FYI, you can treat the field like a number, 
including sorting, numeric functions, etc.

For example,

select * from table order by (text_field+0.0)

Steve Musumeche
CIO, Internet Retail Connection
steve@stripped



Dan Nelson wrote:
> In the last episode (Sep 28), Steve Musumeche said:
>   
>> I think this method will work, however, when trying these queries, I get 
>> a SQL syntax error.
>>
>> mysql> select cast('34' AS decimal);
>> ERROR 1064 (42000): 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 'decimal)' at line 1
>>     
>
> The CAST function in mysql 4.1 and older can't cast to DECIMAL.  5.0
> and newer can.  One easy way to convert strings to numbers in older
> mysql's is to add 0 to them:
>
> mysql> select ("1.10" + 0);
> +------------+
> | "1.10" + 0 |
> +------------+
> |        1.1 | 
> +------------+
>
>   

Thread
making varchar field to act like numeric fieldsteve28 Sep
  • RE: making varchar field to act like numeric fieldRajesh Mehrotra28 Sep
  • Re: making varchar field to act like numeric fieldDouglas Sims28 Sep
    • Re: making varchar field to act like numeric fieldSteve Musumeche28 Sep
      • Re: making varchar field to act like numeric fieldDan Nelson28 Sep
        • Re: making varchar field to act like numeric fieldSteve Musumeche28 Sep
RE: making varchar field to act like numeric fieldRajesh Mehrotra28 Sep
  • Partitioning to_hourMichael Gargiullo28 Sep
  • Re: making varchar field to act like numeric fieldChris W28 Sep