Results 1 to 8 of 8

Thread: Conversion of varchar to float

  1. #1
    Join Date
    Oct 2005
    Posts
    17

    Conversion of varchar to float

    Hello,

    I have a varchar field with for example following entry: "000001152,00". This data is being downloaded from a txt file.
    I want to convert this to 1152. Is this something I can do during the download process? And if so, how?

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    How are you downloading the file? What tool are you using. The method to convert depends on the tool

    In plain T-SQL this can be done as

    select cast(replace('000001152,000',',','.') as float)

  3. #3
    Join Date
    Oct 2005
    Posts
    17
    hi skhanal,
    Well, the files are on a secured FTP server, and are downloaded thru a DTS package (i.e."Text File (source)") and then just copied to a table. How should I then convert it?

  4. #4
    Join Date
    Sep 2002
    Posts
    5,938
    You can load data into staging table, convert the data with above code, then move them to target table.

  5. #5
    Join Date
    Oct 2005
    Posts
    17
    good tip!!! txs

  6. #6
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    You can do the conversion in DTS as well using VBScript.

  7. #7
    Join Date
    Oct 2005
    Posts
    17

    Question

    and do you that skhanal

  8. #8
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    Change the transformation to ActiveX transformation and edit the line for the column you want to convert to

    DTSDestination("Column1") = CDbl(Replace(DTSSource("Column1"),",","."))

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •