jump to navigation

Arithmetic overflow error converting varchar to numeric April 23, 2008

Posted by msrviking in Tips & Tricks.
trackback

Sometime last week, I received an email from one of the developers saying that she was unable convert a varchar value of ‘3.43E-07’ to numeric.

I promised that I would help her, and here is what I could do and well she was delighted with the solution. Here is the example, I had given

DECLARE
@T  TABLE (VAL1 VARCHAR(50))
INSERT INTO @T VALUES (‘3.43E-07’)
SELECT * FROM @T
SELECT CONVERT(NUMERIC(38,10),CONVERT(FLOAT,VAL1)) FROM @T

I have been having tough time with the datatype FLOAT in several projects, and I owe you all a separate blog entry on this where in I shall cover the problems and solutions.

Thanks!

Advertisements

Comments»

1. Shyam Viking - May 7, 2008

Yes, it would work. In my script I was just simulating what the developer had in her box.

2. (no name) - May 7, 2008
But wouldn’t the following work just as well?
 
SELECT CONVERT(NUMERIC(38,10),CONVERT(FLOAT,’3.43E-07′))
 
-Bassy
 
 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: