Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2003

    Question Unanswered: To convert VARCHAR to INT

    Hello ,
    How to convert a varchar to an integer in mysql..

    My problem is i have a field with varchar in one table and i want to insert that value into another table with integer value.

    Pls suggest me how to do that

  2. #2
    Join Date
    Feb 2003
    This is quote from MySQL manual

    MySQL automatically converts numbers to strings as necessary, and vice-versa:

    mysql> SELECT 1+"1";
    -> 2
    mysql> SELECT CONCAT(2,' test');
    -> '2 test'

    thus if you just use query:

    insert into table 2 (field_int) select field_string from table 1
    it will work on condition that field_string can be normally converted into number.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts