Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 12th, 2006, 10:26 PM
Registered User
 
Join Date: May 2006
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 .




SELECT
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
FROM
Time t (NOLOCK) LEFT OUTER JOIN
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


 
Old May 13th, 2006, 03:28 AM
Authorized User
 
Join Date: Jun 2003
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

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 %

Gert






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 06: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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.