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.
| Author |
Topic |
|
majidbhutta
Starting Member
13 Posts |
Posted - 2005-11-29 : 07:04:01
|
| i have some confusion. Scenario is that for an Employee to start and end job the following fields are available;Field DataType===== ========Emp_Id Foreign Key}DateTime PrimaryKey }----> Composite Primary key CheckInTime DateTimeCheckOutTime DateTimeInOutStatus bitHoursWorked ?--------> What shoulud be DataType?When an Employee Checks in All fields are set and InOutStatus is set to 1 Except CheckOutTime and HoursWorked.When The Employee checks out InOutStatus is set to 0,CheckOutTime is set and then i have to calculate the HoursWorked (TimeDuaration). Constarins are CheckOutTime is always greater than CheckInTime.(There may be different dates for them as employee gets check in ,Nov 29,2005 on time 17:00 and checksout , Nov 30,2005 on time 03:30).Now according to calculation he worked for 10 hours and 30 minutes .How to calculate this hours worked(only time duration and to which datatype it should be saved in sql) as well as the Stored Procedure for this whole process.Whenever Employee comes his Emp_Id is only known.Thnx in Advance. |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2005-11-29 : 07:34:25
|
quote: HoursWorked ?--------> What shoulud be DataType?
If you only need to keep in terms of hours then use int.If you need to keep in 2 decimal then use decimal(6,2)quote: DateTime PrimaryKey }----> Composite Primary key CheckInTime DateTimeCheckOutTime DateTime
These fields should be datetimeYou should keep CheckInTime & CheckOutTime in both date & time. SQL provide function to calc date difference in day, hour, minutes etc.To calc hours worked, you can use the followingdatediff(hour, CheckInTime, CheckOutTime) ordatediff(minute, CheckInTime, CheckOutTime) / 60.0to calc hour works in decimal -----------------[KH] |
 |
|
|
|
|
|
|
|