# SQL Calculate Percentage[Answered] RSS

## 5 replies

Last post Jul 10, 2013 02:47 PM by novell yang

• khaliqsyed

Member

10 Points

16 Posts

### SQL Calculate Percentage

May 06, 2008 03:54 AM|khaliqsyed|LINK

Hello every one, I am trying to get the total percentage of a column

 Regions Workbooks Required Workbooks Sent Workbooks Returned Workbooks Complete A 20 21 20 18 B 33 33 33 30 C 19 29 18 16 D 9 18 8 8 Totals

Thanks in advance for any tips/solutions.

• ShivaKarthik

Participant

1341 Points

352 Posts

### Re: SQL Calculate Percentage

May 06, 2008 04:15 AM|ShivaKarthik|LINK

Here is the solution

You select each of that value in particular region A,B,C,D and store that in some variables using some condition

Then define another variable for total then you total all these values

define another variable for percentage and divide the above variable by 5

Then return the last variable.

Mark As Answer if this helps you

Further Queries Recommended

Happy Coding

B. Shiva Karthik
Mumbai , India

-------------------------------------------------
Don't Forget to Mark as Answer for the post that helped you.
-------------------------------------------------
• BlogPortalis...

Participant

1793 Points

341 Posts

### Re: SQL Calculate Percentage

May 06, 2008 06:51 AM|BlogPortalist|LINK

Please elaborate what you mean by "get the total percentage of a column". If it's hard to put words on it - please post a similar table as the one you posted, but with your desired result, and I or someone else can most probably come up with a SQL query to help you out.

If this answered your question, be sure to mark it as the answer. Then you give credit to people who help you, and others will know that the question is already answered.
My SQL Server blog (swedish): http://www.underlandet.com/SqlServer
• khaliqsyed

Member

10 Points

16 Posts

### Re: SQL Calculate Percentage

May 06, 2008 12:08 PM|khaliqsyed|LINK

Thank you for your response, I am basically trying to write a stored procedure which calculate the percentage of each column using temp tables to create "Percent Complete" table.

 By the Numbers Regions Workbooks Required Workbooks Sent Workbooks Returned Workbooks Complete A 20 20 20 15 B 33 33 33 27 C 20 19 18 17 D 9 9 8 8 Totals 82 81 79 67 Percent Complete Regions Workbooks Required Workbooks Sent Workbooks Returned Workbooks Complete A 20 100% 100% 75% B 33 100% 100% 82% C 20 95% 90% 85% D 9 100% 89% 89% Totals 82 99% 96% 82%

I appeciate your time and if you could advice how to get the "Workbooks Sent" Percentage for Region A and Total of Region (A,B,C&D), I think I can utilize the same for rest of the "Percentage Complete" Table/Report.

Once again thank you for your time.

• XPSCodes

Contributor

2461 Points

464 Posts

### Re: SQL Calculate Percentage

May 06, 2008 04:22 PM|XPSCodes|LINK

Queries would look something like this:

select cast(WorkbooksSent as decimal(11,2))/WorkbooksRequired * 100 as PWorkbooksSent
From TableName

select cast(Sum(WorkbooksSent) as decimal(11,2))/Sum(WorkbooksRequired) * 100 as PWorkbooksSentTotal
From TableName

Save our world, its all we have! A must watch video Pale Blue Dot

• novell yang

None

0 Points

1 Post

### Re: SQL Calculate Percentage

Jul 10, 2013 02:47 PM|novell yang|LINK

Good afternoon,

I happened to find your SQL code to resolve the Percentage problem and I have a similar question with a different property. Could you please help me with it?

Here is my question: I am trying to get the percentage (%) of the total SQFT column for each record and name the added-in calculation column as "Allocation". For example, A is occupied 24%  of the Total SQFT (=round(20/82,2). I need to build up the calculation column "Allocation". Please have a look at the table below.

Thank you very much for your time and help in advance!

 Regions SQFT Allocation A 20 24% B 33 40% C 20 24% D 9 11% Totals 82 100%

Percentageoftotalforeachrecord