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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

varchar (20) to a number

Status
Not open for further replies.

Chumley40

Programmer
Jan 24, 2005
71
0
0
US
I have a varchar (20) field with values like:
0.857142857142857

I need to convert it to a number (keeping the accuracy) but keep getting an arithmetic overflow error.

Can anyone help me?

Thanks!
TJ
 
When you say, "convert it to a number", what do you mean? There are several number types in SQL Server. There float, real, decimal/numeric, money, int, bigint, etc...


-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
any number type that will work for using to do calculations. I get an error on float, numeric, decimal
 
I don't get an error when I run your example value:

Code:
Declare @Blah varchar(20)
Set @Blah = '0.857142857142857'

Select Convert(float, @Blah)

Therefore, I assume there are values in this varchar(20) column that cannot be converted to a number. For example, if you had the value [!]'Seven'[/!], you would get a conversion error. To find these bad values, run the following query.

Code:
Select   YourColumnName
From     YourTable
Where    IsNumeric(YourColumnName) = 0


-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top