Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
goodman2253
Yak Posting Veteran
88 Posts |
Posted - 2012-03-06 : 04:27:28
|
| Hi All,I am stuck with an problem and want your helpWhat i want to do is-I have a query which gives the result asNAME--ValueA------1B------2C------3D------4 E------5What i want to do is I have to count the total number of Value Columns(1+2+3+4+5)=15and expected output isNAME--Value--%ageA------1-----6.66%B------2-----13.33%C------3-----20.00%D------4-----26.66%E------5-----33.33% |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-03-06 : 04:32:17
|
[code][%age] = Value * 100.0 / sum(Value) over ()[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
goodman2253
Yak Posting Veteran
88 Posts |
Posted - 2012-03-06 : 06:01:04
|
| Thanks..:) |
 |
|
|
goodman2253
Yak Posting Veteran
88 Posts |
Posted - 2012-03-06 : 06:31:33
|
| Hi one more thing this function should give as output6.66%13.33%20.00%26.66%33.33% |
 |
|
|
goodman2253
Yak Posting Veteran
88 Posts |
Posted - 2012-03-06 : 06:33:08
|
| After a decimal only two character allowed with % sign |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-03-06 : 06:47:18
|
you can use ROUND ( <number> , 2 ) to round it to 2 decimal placesorconvert(decimal(10,2) <number> ) to convert itHowever, % is a display / formatting issue. Formatting should be performed at your front end application KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
goodman2253
Yak Posting Veteran
88 Posts |
Posted - 2012-03-06 : 06:59:55
|
| Round function give as output6.660000013.330000But I want the output as6.6613.33 |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-03-06 : 07:07:17
|
i have provided 2 method there. Have you try the other one ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|