Exe SQL Task - Convert float to varchar

  • I'm trying to update a varchar column from a float column, with the following query:

    update dbo.tblChxDDA

    set cvt_Tax_ID_Number = CAST(CAST(Tax_ID_Number AS DECIMAL(20,0)) AS VARCHAR)

    When I run this through the SSIS package my results are as follows:

    floatColumn varcharColumn

    431511964 1512e+008

    But when i run the update through SSMS, it works fine (the expected result):

    floatColumn varcharColumn

    431511964 431511964

    Has anyone run into this issue? Thanks

  • Have you tried using a derived column with the correct target data type as opposed to casting it in the SQL statement?

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • Just curious, why are you casting your input to a decimal and then to VARCHAR?

    If you're trying to convert a numerical data type to a SSN or tax ID, try the following:

    RIGHT('000000000' + RTRIM(CAST(Tax_id_number AS VARCHAR)), 9)

    Tim Mitchell, Microsoft Data Platform MVP
    Data Warehouse and ETL Consultant
    TimMitchell.net | @Tim_Mitchell | Tyleris.com
    ETL Best Practices

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

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