Error converting data type varchar to float

  • I've a table with one column as varchar(50). This table is hugely populated. I want to alter this column to datatype float. While altering it gives me the following error:

    Error converting data type varchar to float.

    Kindly let me know what can be done as quick fix ?

  • sqlnaive (9/11/2012)


    I've a table with one column as varchar(50). This table is hugely populated. I want to alter this column to datatype float. While altering it gives me the following error:

    Error converting data type varchar to float.

    Kindly let me know what can be done as quick fix ?

    Can you post a sample of the data? You will have to find the rows which contain data which cannot be implicitly converted to float and deal with them.

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • You are going to have to identify the data that won't convert.

    Modify as needed and run this:

    select

    *

    from

    dbo.YourTable

    where

    ColumnToConvert like '%[^0-9]%';

  • Thanks both Chris and Lynn. I was checking and found that there were few records having populated as 'NULL' string. Thats why it was causing issue. Rectified it and now all is fine. Thanks once again.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply