Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 varchar(50) to decimal(24, 4)

Author  Topic 

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2007-07-24 : 08:53:30
Hi,
I would like to insert the following figures (which are held in a varchar(50) datatype field) into a field of type decimal(24, 4)

5.55111512312578e-017
4.00000000020384e-005
4.99999999981071e-005
1.38777878078145e-017

How can I do this please?

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2007-07-24 : 08:55:33
When using
convert(decimal(24, 4), [Column 9])
the error is:
Error converting data type varchar to numeric.
Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2007-07-24 : 09:21:03
Found what causes the error:
I think it is to do with the fact that one row contains '1e-006'
and when running the following query the error is produiced.

error:
Error converting data type varchar to numeric.

What is wrong with this number though?

select convert(decimal(24, 4), '1e-006')
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2007-07-24 : 09:59:49
Most of these are basically zeroes, and SQL can't convert them into NUMERIC(p,s) because it doesn't have the precision. If you do select convert(decimal(38, 37),convert(real, [col9]))
you will see that all of your answers are < .000001, which are all 0.0000 in decimal(24,4)
Jim
Go to Top of Page
   

- Advertisement -