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
 General SQL Server Forums
 New to SQL Server Programming
 converting/cast varchar to numeric with scale

Author  Topic 

lwildeck
Starting Member

1 Post

Posted - 2013-09-01 : 12:04:44
I have a varchar(len=9) field that I want to cast as numeric(9,2). Some of the field values are null but some have valid values (ie 1.00 or .05).

I am selecting data from one table and then updating a different table.

I have a select statement within an insert statement and then an update statement. I've tried a cast statement but not successfully. I get the following error.

[Execute SQL Task] Error: Executing the query "Exec sp_ESTLoadPOData" failed with the following error: "Error converting data type varchar to numeric.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.

Any suggestions?

bitsmed
Aged Yak Warrior

545 Posts

Posted - 2013-09-01 : 17:23:48
Find non numeric and deal with them first:

select *
from yourtable
where isnumeric(yourfield)<>1
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-09-02 : 08:34:53
ISNUMERIC is not fully reliable. So depending on your requirement you might have to use additional conditions too

see

http://beyondrelational.com/modules/2/blogs/70/posts/10803/enhanced-isnumeric-function.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-09-02 : 08:35:52
for your specific scenario where did you do the cast? Is the procedure having parameters?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -