Divide column values

  • Hi,

    I have these two columns

    select

    '$ '+REPLACE(CONVERT(VARCHAR(32),cast(round(Total_Amount,2)as MONEY),1), '.00', '') as Total_Amount,

    '$ '+REPLACE(CONVERT(VARCHAR(32),cast(round(Monthly_Amount,2)as MONEY),1), '.00', '') as Monthly_Amount

    from Finance

    Now Monthly_Amount column should have calculated values like Total_Amount/12

  • vigneshkumart50 (5/7/2014)


    Hi,

    I have these two columns

    select

    '$ '+REPLACE(CONVERT(VARCHAR(32),cast(round(Total_Amount,2)as MONEY),1), '.00', '') as Total_Amount,

    '$ '+REPLACE(CONVERT(VARCHAR(32),cast(round(Monthly_Amount,2)as MONEY),1), '.00', '') as Monthly_Amount

    from Finance

    Now Monthly_Amount column should have calculated values like Total_Amount/12

    Is this what you are after?

    😎

    select

    '$ '+REPLACE(CONVERT(VARCHAR(32),cast(round(Total_Amount,2)as MONEY),1), '.00', '') as Total_Amount,

    '$ '+REPLACE(CONVERT(VARCHAR(32),cast(round(Total_Amount,2)as MONEY) / 12,1), '.00', '') as Monthly_Amount

    from Finance

  • yes also for monthly_amount I need to have two decimal values

    Like

    $ 134,98.55

    $ 41.34

  • Just move the division inside the round function.

    😎

  • like this

    '$ '+REPLACE(CONVERT(VARCHAR(32),cast(round(Total_Amount,2)/12 as MONEY),1), '.00', '') as Monthly_Amount,

  • More like this

    '$ '+REPLACE(CONVERT(VARCHAR(32),cast(round((Total_Amount/12),2) as MONEY),1), '.00', '') as Monthly_Amount,

    😎

  • vigneshkumart50 (5/7/2014)


    like this

    '$ '+REPLACE(CONVERT(VARCHAR(32),cast(round(Total_Amount,2)/12 as MONEY),1), '.00', '') as Monthly_Amount,

    why CAST as MONEY and then REPLACE....couldn't you just cast as INT?

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

  • J Livingston SQL (5/7/2014)


    vigneshkumart50 (5/7/2014)


    like this

    '$ '+REPLACE(CONVERT(VARCHAR(32),cast(round(Total_Amount,2)/12 as MONEY),1), '.00', '') as Monthly_Amount,

    why CAST as MONEY and then REPLACE....couldn't you just cast as INT?

    That would be implicit rounding:cool:

Viewing 8 posts - 1 through 7 (of 7 total)

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