Wednesday, April 27, 2011

Find and Fix Scientific Notation values in a field

Many years ago during some importing or upgrading to a bigger better database one of my fields was converting longer numerical values to scientific notation.  This quit happening but I still had alot of those values in a text field in my database. Originally that field was numeric, but we converted it to text because there were often times when letters were added to the values we receive.

After not being able to find a isScientificNotation() function I found the values like this:

select myfield, LTRIM(str(cast(my field as real))), * from mytable

This worked great and made it easy to write an update statement like so:

update mytable
set myfield = LTRIM(str(cast(myfield as real)))
where myfield like '%e+%'

No more scientific notation in my field. Cool. Should have fixed this years ago, or not let it happen in the first place.

Dave