Forum Moderators: open

Message Too Old, No Replies

Converting Varchar to Decimal MSSQL 2000

         

trancehead

9:57 am on Mar 8, 2006 (gmt 0)

10+ Year Member



Hi,

I am continually getting the error message : [Microsoft][ODBC SQL Server Driver][SQL Server]Error converting data type varchar to numeric.
When trying to run this SQL statement :
SELECT * FROM table WHERE CAST(Field1 AS DECIMAL(10,1)) >= 1

Field1 is Varchar(3) with data such as 3.5 or 4 in it (it is a rating system).

Any ideas?

txbakers

11:39 am on Mar 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



welcome to the webmaster world!

Can't tell right away why the error, but a thought - if you are storing numeric data in the field, why not make it a decimal datatype from the get go? That would avoid the cast argument.

The error could come from the DB trying to convert a null, or a non-numeric value.

aspdaddy

5:22 pm on Mar 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You have at least 1 value that cannot be converted to decimal. Run this statement to find the problem:

SELECT Field1,isNumeric(Field1)
FROM table
WHERE isNumeric(Field1)=0