Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Select Help

Author  Topic 

eljapo4
Posting Yak Master

100 Posts

Posted - 2012-04-26 : 11:30:06
Hi - I have to separate jobs but I want to sum the total minutes spent for both jobs, the D1_Factor_PC is different for the 2 jobs my query is returning me 2 rows instead of one can anyone help please?
SELECT 	SUM(dbo.tbl_Daily_Timesheet.EffectiveMinutes * D1_Factor_PC)/100 [Personal Needs RECOVERY]
FROM dbo.tbl_Daily_Timesheet
INNER JOIN dbo.tbl_Job_D1_Factors ON dbo.tbl_Daily_Timesheet.WorkstudyCode = dbo.tbl_Job_D1_Factors.Job_Code
INNER JOIN dbo.tbl_D1_Factors ON dbo.tbl_Job_D1_Factors.D1_Factor_ID = dbo.tbl_D1_Factors.D1_Factor_ID
WHERE tbl_Job_D1_Factors.D1_Factor_ID = '1' --Personal Needs
GROUP BY dbo.tbl_Daily_Timesheet.EffectiveMinutes
,dbo.tbl_Job_D1_Factors.D1_Factor_PC

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-04-26 : 11:34:38
Remove the grouping
SELECT
SUM(dbo.tbl_Daily_Timesheet.EffectiveMinutes * D1_Factor_PC) / 100
[Personal Needs RECOVERY]
FROM
dbo.tbl_Daily_Timesheet
INNER JOIN dbo.tbl_Job_D1_Factors
ON dbo.tbl_Daily_Timesheet.WorkstudyCode = dbo.tbl_Job_D1_Factors.Job_Code
INNER JOIN dbo.tbl_D1_Factors
ON dbo.tbl_Job_D1_Factors.D1_Factor_ID = dbo.tbl_D1_Factors.D1_Factor_ID
WHERE
tbl_Job_D1_Factors.D1_Factor_ID = '1' --Personal Needs
Go to Top of Page

eljapo4
Posting Yak Master

100 Posts

Posted - 2012-04-26 : 11:49:10
Thank you sunitabeck
Go to Top of Page
   

- Advertisement -