float to varchar

  • I have fax number in two tables. I need to update data from tableA to tableB.

    fax_number column in tableA is of varchar and in tableB it is float.

    so when the fax number value in tableB is 7778889999 and when run my update statement this value is updated as

    7.77888e+009.

    How can I update with the same format- 7778889999

    The tables are on sql server 2008.

    Thanks.

  • sql_novice_2007 (10/21/2011)


    I have fax number in two tables. I need to update data from tableA to tableB.

    fax_number column in tableA is of varchar and in tableB it is float.

    so when the fax number value in tableB is 7778889999 and when run my update statement this value is updated as

    7.77888e+009.

    How can I update with the same format- 7778889999

    The tables are on sql server 2008.

    Thanks.

    A fax number, like a telephone number, isn't a number at all - it's an identification string which coincidentally often contains numerics. It can have embedded spaces and may well have leading zeros. So why use float?

    “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

  • the data type in source table is float and when I update this info in tableB which has a varchar data type it's converting to 7.77888e+009. I need to update this info as 7778889999 into varchar column.

    I can't change the data type in source table tableA.

    Thanks.

  • Does anyone has any ideas of updating this value as a number into varchar field by not converting into 7.77888+e009

    Thanks.

  • one way that may work for you, dependent upon the data.....

    SET fax_number_varchar = CAST(fax_float as int)

    ________________________________________________________________
    you can lead a user to data....but you cannot make them think
    and remember....every day is a school day

  • sql_novice_2007 (10/24/2011)


    Does anyone has any ideas of updating this value as a number into varchar field by not converting into 7.77888+e009

    Thanks.

    Look up the STR() function in Books Online. The STR() function accepts a float parameter, which can mean a loss of precision (read this excellent article by Jeff Moden[/url]), but in your case the value is already of type float.

    “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

Viewing 6 posts - 1 through 5 (of 5 total)

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