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 2005 Forums
 Transact-SQL (2005)
 Manipulating SP for Certain times(Dates)

Author  Topic 

kamnandi
Starting Member

6 Posts

Posted - 2010-10-29 : 09:05:32
I am farely new to SP's and below is a time and attendance system. If someone clocks in then clocking time is set to getdate() and status is 1 to indicate he was clocked in. When they punch out again clocking out time is set to getdate() and status =2 which indicates he is clocked out.

What I want this SP to do is to check if clockin time is later than 08h00. if they clock in at 07h45 it should default to 08h00 but if he comes in at 08h30 is should use that specific value. The same principle for clocking out if they clock out 17h20 it should default to 17h00 but if the clock out at 16h10 it should use this value. Thx for your time.

ALTER PROCEDURE [dbo].[spClocking]
(
@staffNo varchar(50)
)
AS
BEGIN
Declare @Status varchar(50), @ClockIn datetime, @ClockOut datetime, @Minutes decimal, @ClockID int
SET NOCOUNT ON;
select @ClockID = (Select top 1 ClockingID from Clocking where StaffID = @StaffNo order by ClockingID desc)
Select @Status = (Select Status from Clocking where ClockingID = @ClockID)
-- Insert statements for procedure here
IF @Status = 1
BEGIN
select @ClockIn = (Select ClockTime_In from Clocking where ClockingID = @ClockID)
select @ClockOut = getDate()
select @Minutes = datediff(minute, @ClockIn, @ClockOut)

update Clocking set Status = 2, ClockTime_Out = @ClockOut, Minutes = @Minutes where ClockingID = @ClockID
END
ELSE
BEGIN
select @ClockIn = getDate()
select @Status = 1

insert into Clocking (StaffID, Status, ClockTime_In)
values (@staffNo, @Status, @ClockIn)
END
END

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-11-01 : 12:30:52
what are datatypes of clockin and clockout fields?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

kamnandi
Starting Member

6 Posts

Posted - 2010-11-06 : 07:36:19
Hi There

It is Datetime

Thx
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-11-10 : 10:55:15
see the logic used below

http://visakhm.blogspot.com/2010/03/calculating-business-hours.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -