Convert a scientific notation varchar to a decimal field in MS-SQL

Posted on 2005-05-13
Last Modified: 2008-01-09
Hi there;

I have a field in my table (I'm using MS-SQL) that is a varchar, in it is a scientific notation like : 3.5E+1. I now want to update a decimal field with this number, in this case it would be inserted in the decimal field as 35.  I tried to use cast but it doesn't work.

Has anyone done this before? Can you help?
Question by:IngridK
    LVL 28

    Accepted Solution

    Try casting it first to float then to decimal:

    select CAST(cast('3.5E+1' as float) AS DECIMAL(18, 4))

    Author Comment

    That was great, thank you. Used it in my query to update.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now