Click here to Skip to main content
15,885,159 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i have two tables employee and timesheet-

employee contains-employeeid,employeename
timesheet contains-employeeid,startdate,enddate,hourstaken

user enter multiple records on a same day.

now i want which employees hourstaken is less then n hours.

suppose i want date-01/03/2012 and hourstaken = 5hr

so i want how many employees are not working atleast 5 hr on a 01/03/2012

In a result i want -
employeename,startdate,hourstaken


i am using this querry it gives employeeid i want employeename instead of employeeid

C#
select convert(VARCHAR, '2012/02/18', 111) as startdate, sum(hourstaken) as hourstaken,employeeid
from timesheet where convert(VARCHAR, startdate, 111) = '2012/02/18'
group by employeeid having sum(hourstaken) < '5'


Thanks
Posted
Updated 2-Mar-12 19:12pm
v2
Comments
The Doer 3-Mar-12 1:31am    
if you want employee name then use joins between those two tables

hi there....

if u already have value for the total hours column in your timesheet then try this...

SQL
SELECT e.employeeid,e.employeename,t.startdate,SUM(t.hourstaken)
FROM employee e INNER JOIN timesheet t
ON e.employeeid=t.employeeid
GROUP BY e.employeeid,e.employeename,t.startdate
HAVING SUM(t.hourstaken)< 5




hope this helps...

revert back with ur comments...
 
Share this answer
 
v3
Comments
soothingshruti 3-Mar-12 2:17am    
Thanks a lot Rajdeep
rajdeep kumar 3-Mar-12 2:34am    
most welcome..
SQL
alter procedure NoOfEmpWorkingLess @date datetime,@hrsTaken int
AS
select e.employeename,t.startdate,sum(t.hourstaken) from timesheet t
inner join
employee e on e.employeeid=t.employeeid
 where startdate=@date  group by e.employeename,t.startdate
having sum(hourstaken)>@hrsTaken





Welcome back,
All the best.
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900