Click here to Skip to main content
15,889,879 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
im a newbie,
i am using sql server 2005

i have a attendance_tbl 3 fields(columns),

table defn :
in_time datetime not null,-- unique key
out_time datetime null,
emp_id int null -- foreign key

table is used for storing employee in_time and out_time

i am inserting in_time and emp_id for corresponding employee when employee enters,

and update the out_time columns for employee logout,

PROBLEM is when i update the table for out_time all the records corresponding the that employee get updated, i mean all records out_time get updated
Posted

1 solution

When updating the record for that employee for out-time, check the in-time date only, It should be todays date. then update it.

you can try below query
update [table-name] set out-time=[Out-Time]
where in-time= DATEADD(dd,0,DATEDIFF(dd,0,GETDATE())))
 
Share this answer
 
Comments
gospidey 22-May-10 4:46am    
thanx vaishali for solving my query,thanx a ton....

i modified the query a bit... to match my requirement

update attendance_tbl set out_time=getdate()
where emp_id=1 and DATEADD(dd,0,DATEDIFF(dd,in_time,GETDATE()))=0
gospidey 22-May-10 4:48am    
the modification ? is it fine... i think the update should occur only if date_difference is zero rite...? thanx again - gospidey

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