Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Covert Decimal to Int 1

Status
Not open for further replies.

aumstu

MIS
Joined
Jan 20, 2006
Messages
40
Location
US
I am trying to convert decimal numbers into a number without decimals…

Sample Data
Code:
Now	Needs to Be
23.00	2300
68.67	6867
42.36	4236

All the decimals are two places.

I have used this sql statement to view the data

Code:
select table_hours, cast((table_hours * 100) as int) AS NewHours
From table

This pulls back the correct format that I want…but when I try to use the update I get the following error.

Code:
Server: Msg 8115, Level 16, State 8, Line 1
Arithmetic overflow error converting numeric to data type numeric.
The statement has been terminated.

Here is my update statement

Code:
Update TABLE
SET TABLE_HOURS = cast((table_hours * 100) as int)

Does anyone know how I can update these field with the new format?

Thanks
 
run this to find out scale and precision
also what is the table name?

select numeric_precision,numeric_scale
from information_schema.columns
where column_name ='table_hours'
--and table_name ='table ' -??

Denis The SQL Menace
SQL blog:
Personal Blog:
 
Thanks sqldenis...Is the precision that the decimal place could be to?

the results are

5 2

The name of the table is SDBHOURS

thanks
 
thanks...

the math is working but whenever I the decimal places are still in the field.

The reason I havn't changed to a int is because of the decimal places. The data is imported using a dts package. I think that I will change the field to a int and then multiply by 100 in the dts package.

thanks again
 
Denis, wouldn't that just truncate off the 2 digits to the right of the decimal? Or will it shift the decimal? And, what will happen to 12.34 if it is cast as int? This: 1234 or this: 12
You are a great teacher, and george and vongrunt and sqlsister, SQLbill and many others. You are appreciated!

"You cannot hold a torch to another man's path without brightening your own"
Best regards,
Bill
 
And you jbenson!

"You cannot hold a torch to another man's path without brightening your own"
Best regards,
Bill
 
Thanks again for all your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top