Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sum adding up total value

Status
Not open for further replies.

jancheta

Programmer
Aug 30, 2002
51
0
0
US
Hello. I'm trying to retrieve the hours worked for each employee however i'm getting the total for the employee in a month.

Example:
Name Jan Feb Mar
---- --- --- ---
Joe 0 480 0
Tony 0 0 480
Sue 480 0 0

Output that I'm trying to get is (each employee worked 8hrs/day:
Name Jan Feb Mar
---- --- --- ---
Joe 160 160 160
Tony 160 160 160
Sue 160 160 160

Here are my tables:
tblemployee fields
-----------
employeeid
name

tblwork fields
-----------
workid
workdate
employeeid

tblhours fields
-----------
workid
hoursworked
SQL:
select tblemployee.name,
sum(tblhours.hoursworked) * (1-ABS(SIGN(dayofmonth(tblwork.workdate)-1))) AS Jan,
sum(tblhours.hoursworked) * (1-ABS(SIGN(dayofmonth(tblwork.workdate)-2))) AS FEb,
sum(tblhours.hoursworked) * (1-ABS(SIGN(dayofmonth(tblwork.workdate)-3))) AS Mar,
sum(tblhours.hoursworked) * (1-ABS(SIGN(dayofmonth(tblwork.workdate)-4))) AS Apr,
sum(tblhours.hoursworked) * (1-ABS(SIGN(dayofmonth(tblwork.workdate)-5))) AS May
FROM (tblemployee INNER JOIN tblWork ON tblemployee.employeeid = tblWork.employeeid) INNER JOIN tblHours ON tblwork.workid = tblhours.workid
Group by tblemployee.name;
 
Geez, I was using the incorrect function. Supposed to be month and not dayofmonth.

Regards.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top