SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Percent - 2 Decimal
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 05/02/2008 :  09:12:34  Show Profile  Reply with Quote
Hi,

How can I convert my number results to Percent (%) with 2 decimal places?

Thanks

harsh_athalye
Flowing Fount of Yak Knowledge

India
5509 Posts

Posted - 05/02/2008 :  09:13:44  Show Profile  Visit harsh_athalye's Homepage  Click to see harsh_athalye's MSN Messenger address  Send harsh_athalye a Yahoo! Message  Reply with Quote
Post full sample data and expected output.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 05/02/2008 :  09:16:25  Show Profile  Reply with Quote
select* sum(data)/count(data) as results
From Data
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22754 Posts

Posted - 05/02/2008 :  09:21:14  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
quote:
Originally posted by cutiebo2t

select* sum(data)/count(data) as results
From Data



select cast(sum(data)/count(data)*1.0 as decimal(12,2)) as results
From Data


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 05/02/2008 :  09:31:35  Show Profile  Reply with Quote
thanks but can it be in percentage form. Example 34.56%.
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22754 Posts

Posted - 05/02/2008 :  09:37:41  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
quote:
Originally posted by cutiebo2t

thanks but can it be in percentage form. Example 34.56%.


That should be shown in your front end application

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 05/02/2008 :  09:38:52  Show Profile  Reply with Quote
oh i see. So it's not possible with SQL?
Go to Top of Page

harsh_athalye
Flowing Fount of Yak Knowledge

India
5509 Posts

Posted - 05/02/2008 :  09:40:18  Show Profile  Visit harsh_athalye's Homepage  Click to see harsh_athalye's MSN Messenger address  Send harsh_athalye a Yahoo! Message  Reply with Quote
It is possible but not advisable to do in SQL.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 05/02/2008 :  09:43:34  Show Profile  Reply with Quote
may i know how? thanks
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22754 Posts

Posted - 05/02/2008 :  09:58:15  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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 calculations

Where do you want to show data?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 05/03/2008 :  05:34:23  Show Profile  Reply with Quote
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 results
From Data
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 05/03/2008 :  06:05:24  Show Profile  Reply with Quote
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 results
From Data


Better to do this formatting at your front end application
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22754 Posts

Posted - 05/03/2008 :  07:13:45  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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 results
From Data


How do I add 10 to that result?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000