Author |
Topic |
cutiebo2t
Constraint Violating Yak Guru
256 Posts |
Posted - 2008-05-02 : 09:12:34
|
Hi,How can I convert my number results to Percent (%) with 2 decimal places?Thanks |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-05-02 : 09:13:44
|
Post full sample data and expected output.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
|
|
cutiebo2t
Constraint Violating Yak Guru
256 Posts |
Posted - 2008-05-02 : 09:16:25
|
select* sum(data)/count(data) as resultsFrom Data |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-05-02 : 09:21:14
|
quote: Originally posted by cutiebo2t select* sum(data)/count(data) as resultsFrom Data
select cast(sum(data)/count(data)*1.0 as decimal(12,2)) as resultsFrom DataMadhivananFailing to plan is Planning to fail |
|
|
cutiebo2t
Constraint Violating Yak Guru
256 Posts |
Posted - 2008-05-02 : 09:31:35
|
thanks but can it be in percentage form. Example 34.56%. |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-05-02 : 09:37:41
|
quote: Originally posted by cutiebo2t thanks but can it be in percentage form. Example 34.56%.
That should be shown in your front end applicationMadhivananFailing to plan is Planning to fail |
|
|
cutiebo2t
Constraint Violating Yak Guru
256 Posts |
Posted - 2008-05-02 : 09:38:52
|
oh i see. So it's not possible with SQL? |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-05-02 : 09:40:18
|
It is possible but not advisable to do in SQL.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
|
|
cutiebo2t
Constraint Violating Yak Guru
256 Posts |
Posted - 2008-05-02 : 09:43:34
|
may i know how? thanks |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-05-02 : 09:58:15
|
quote: Originally posted by cutiebo2t may i know how? thanks
You have to convert the value to varchar and it is not possible to use that value in any arithmetic calculationsWhere do you want to show data?MadhivananFailing to plan is Planning to fail |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2008-05-03 : 05:34:23
|
quote: Originally posted by cutiebo2t thanks but can it be in percentage form. Example 34.56%.
select cast(cast(sum(data)/count(data)*1.0 as decimal(12,2))as varchar(50))+'%' as resultsFrom Data |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-03 : 06:05:24
|
quote: Originally posted by raky
quote: Originally posted by cutiebo2t thanks but can it be in percentage form. Example 34.56%.
select cast(cast(sum(data)/count(data)*1.0 as decimal(12,2))as varchar(50))+'%' as resultsFrom Data
Better to do this formatting at your front end application |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-05-03 : 07:13:45
|
quote: Originally posted by raky
quote: Originally posted by cutiebo2t thanks but can it be in percentage form. Example 34.56%.
select cast(cast(sum(data)/count(data)*1.0 as decimal(12,2))as varchar(50))+'%' as resultsFrom Data
How do I add 10 to that result? MadhivananFailing to plan is Planning to fail |
|
|
|