Format values as Percent

  • Don't know if you are still looking for an answer, but this should work for you:

    Select MyColumn FROM

    (

    SELECT right(replicate('0',5) +CAST(CAST(0.10*100 AS numeric(10,2)) AS varchar(5)), 5) + '%' as MyColumn

    Union

    SELECT right(replicate('0',5) +CAST(CAST(0.011*100 AS numeric(10,2)) AS varchar(5)), 5) + '%' as MyColumn

    Union

    SELECT right(replicate('0',5) +CAST(CAST(0.02*100 AS numeric(10,2)) AS varchar(5)), 5) + '%' as MyColumn

    Union

    SELECT right(replicate('0',5) +CAST(CAST(0.12*100 AS numeric(10,2)) AS varchar(5)), 5) + '%' as MyColumn

    ) MyTable

    Order by CAST(Replace(MyColumn,'%','') as DECIMAL) asc

    --------
    For SQL Tips, check out my blog: http://lantztechknowledge.blogspot.com/[/url]
    You can also follow my twitter account to get daily updates: @BLantz2455

Viewing post 16 (of 15 total)

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