?
Solved

how can I get a percentual in my query from a total field?

Posted on 2011-04-19
7
Medium Priority
?
316 Views
Last Modified: 2012-06-27
Hello guys

I have this query:

SELECT CLIENT, TOTAL FROM SELL

Unless I have the Total, I want the percentual

is it possible? thanks
0
Comment
Question by:hidrau
7 Comments
 
LVL 16

Assisted Solution

by:Imran Javed Zia
Imran Javed Zia earned 200 total points
ID: 35424058
hi,
I don't think if there is any builtin method for percentile

but you can follow follwoing links for help:
http://www.devx.com/dbzone/Article/35550
Thanks
0
 
LVL 5

Assisted Solution

by:gemailj
gemailj earned 200 total points
ID: 35424245


Declare @sumTotal float
select @sumTotal = sum(TOTAL) from SELL

SELECT CLIENT, TOTAL, (TOTAL / sumTotal) as [Percentage] FROM SELL

Open in new window

0
 
LVL 5

Expert Comment

by:gemailj
ID: 35424254
sorry miss the @ before sumTotal
Declare @sumTotal float
select @sumTotal = sum(TOTAL) from SELL

SELECT CLIENT, TOTAL, (TOTAL / @sumTotal) as [Percentage] FROM SELL

Open in new window

0
Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

 
LVL 22

Accepted Solution

by:
Nico Bontenbal earned 1400 total points
ID: 35424266
Is this what you are looking for:
SELECT CLIENT,  convert(real,total)/convert(real,(select sum(total) from sell))as perc FROM SELL

Open in new window

0
 
LVL 3

Assisted Solution

by:wuyinzhi
wuyinzhi earned 200 total points
ID: 35424278
maybe like this?

select total, (select a.total/sum(total)*100 from sell) as percent from sell a
0
 
LVL 1

Author Closing Comment

by:hidrau
ID: 35424313
THANKS VERY MUCH
0
 
LVL 5

Expert Comment

by:gemailj
ID: 35425740
you must select the sum of Total in a variable separately in-order to enhance performance
0

Featured Post

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question