Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Display Modes
  #1 (permalink)  
Old May 12th, 2006, 10:26 PM
Registered User
Join Date: May 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to calculate the percentage in sql

In the below select statement the client wants to have percentage of (t.regularhours) instead of sum(t.regularhours) how to calculate thepercentage please help me out .

ISNULL(w.Name, 'N/A') AS WorkGroupName,
'Project' as TimeType,

case when res.employeetype ='NT' then 'NTNI'
when res.employeetype= 'EM' then 'Employee'
when res.employeetype= 'CO' then 'Contractor'
when res.employeetype= 'MC' then 'Management Consultant'
when res.employeetype= 'OS' then 'Offshore'
end Employeetype,
Sum(t.RegularHours) AS RegularHours
Workgroupmember wgm (NOLOCK) ON t.ResourceId = wgm.ResourceId and t.WorkgroupId=wgm.WorkgroupId and t.GlobalWorkgroupId=wgm.GlobalWorkgroupId LEFT OUTER JOIN
Workgroup w (NOLOCK) ON w.WorkgroupId = wgm.WorkgroupId and w.deleted = 0 LEFT OUTER JOIN
GlobalWorkgroup gwg (NOLOCK) ON wgm.GlobalWorkgroupId = gwg.GlobalWorkgroupId LEFT OUTER JOIN
Resources res (NOLOCK) ON wgm.ResourceId = res.ResourceId
where timedate >'12/10/2005' and approvalstatus='A' and w.obs like '00001.00004.00001%'
group by w.name,res.employeetype

Reply With Quote
  #2 (permalink)  
Old May 13th, 2006, 03:28 AM
Authorized User
Join Date: Jun 2003
Location: , , Norway.
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts


The percentage of (t.regularhours) in relation to what? You need to have a base in order to calculate percentage.

If you have 10 hours, it doesn't make sence to say: "how many percentage is 10 hours". You could say "how many percentage of the total hours in a day is 10 hours?" Then the answer would be 10.0 / 24 * 100 = 41.666 %


Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL - Computing percentage of total ace2e SQL Language 8 October 31st, 2014 10:42 AM
Calculate Percentage with Date mateenmohd Access 2 February 4th, 2008 05:26 AM
SQL for records that contain a percentage sign lukeb Oracle 2 June 12th, 2006 08:04 PM
Calculate a difference percentage skwilliams Classic ASP Basics 15 April 4th, 2006 06:46 AM
percentage darkhalf Javascript 2 October 28th, 2005 02:55 PM

All times are GMT -4. The time now is 05:34 PM.

Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.