Convert varchar(50) to money or decimal

  • Hi everyone:

    I'm getting files (A) with a column representing money as

     (A)                               (B) 

    +002345 which equals to $23.45

    or

    -002345 which equals to -$23.45

    How to convert varchar(50) data to the right decimal or money format like $23.45 or -$23.45? I could accept 23.45 or -23.45 as decimals. Important part, I have to convert that during INSERT INTO table B.

    RGDS

    Sam

     

     

     

     

  • Something like this?

    declare @a varchar(50), @b-2 varchar(50)

    set @a = '+002345'

    set @b-2 = '-002345'

    select cast(@a as decimal(19,2)) as 'a', cast(@b as decimal(19,2)) as 'b'

    Regards

    Phil

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • By the way, this forum is for discussing the Question of the Day not for individual's questions. The QOD is a test question that you can view by selecting Resources > Question of the Day.

    Please post your questions in appropriate forums in the future.

    Thanks,

    -SQLBill

  • Hi Phil,

    I been advised to post this question to General Forum. Check this forum for the same question. Thank you for your post. Running your quiery produced

    2345.00 instead of 23.45

    I would like your follow up on that.

    RGDS

    Sam

     

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

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