Bluehost.com Web Hosting $6.95

cast function problems

This is a discussion on cast function problems within the MySQL Database forums, part of the Database Forums category; Hi, In one of my tables, one of the columns (Salary) is of type varchar(255). I want to conver ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2007
PGPS
 
Posts: n/a
Default cast function problems

Hi,
In one of my tables, one of the columns (Salary) is of type
varchar(255). I want to conver it into int(11). When I do a test to
see if get the result, I have the following problems.

select cast(Salary as unsigned int) from mydb;

Truncated incorrect INTEGER value: '150000.00'


ie, if the Salary has a decimal point, it gives me an error. Any
suggestions?

Thanks.

Reply With Quote
  #2 (permalink)  
Old 04-17-2007
PGPS
 
Posts: n/a
Default Re: cast function problems

Actually, I am trying to insert this salary value ( from varchar(255))
into a table which has a type int(11). Thats when I get this trouble.
insert into mydb2 (select cast(Salary as unsigned int) from mydb)

Truncated incorrect INTEGER value: '150000.00'

mydb2 has Salary int(11);

Thanks.

On Apr 17, 5:39 pm, PGPS <premg...@gmail.com> wrote:
> Hi,
> In one of my tables, one of the columns (Salary) is of type
> varchar(255). I want to conver it into int(11). When I do a test to
> see if get the result, I have the following problems.
>
> select cast(Salary as unsigned int) from mydb;
>
> Truncated incorrect INTEGER value: '150000.00'
>
> ie, if the Salary has a decimal point, it gives me an error. Any
> suggestions?
>
> Thanks.



Reply With Quote
  #3 (permalink)  
Old 04-18-2007
PGPS
 
Posts: n/a
Default Re: cast function problems

Found the solution myself, the problem was solved if I convert the
varchar to decimal and then to integer

cast(cast(SalaryMin as decimal(8,0)) as unsigned integer


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:10 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0