Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Exe SQL Task - Convert float to varchar Expand / Collapse
Author
Message
Posted Thursday, September 3, 2009 12:51 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, June 13, 2014 6:57 PM
Points: 148, Visits: 640
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
Post #782489
Posted Tuesday, September 8, 2009 10:33 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Tuesday, August 19, 2014 10:01 AM
Points: 3,840, Visits: 3,841
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 - by Jeff Moden
Post #784390
Posted Tuesday, September 8, 2009 1:11 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, September 15, 2014 4:46 PM
Points: 1,045, Visits: 2,725
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, SQL Server MVP
Independent Business Intelligence Consultant
www.TimMitchell.net
@Tim_Mitchell

Post #784505
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse