Stored Procedure not saving to database
Hello,
I have a log in web application that is passing an id field to a stored procedure where the log in or log out time is captured and then saved to a database. In the query analyzer everything in the stored procedure pasted below comes out the way that it should but the results are only partially being saved to the database. It will save the id and the log in time but nothing else. If I play with the '@' symbol in the Update statements I can get the log in statement to save but then it overwrites all the log out times. If you are able to see the error(s) in my logic or the problem could you please point me in the direction of how to fix it?
CREATE PROCEDURE dbo.Test28
(
@id char (10)
)
AS
SET NOCOUNT ON
DECLARE @IsUpdate int
DECLARE @totalHour float
DECLARE @totalMinute float
DECLARE @totalSecond float
DECLARE @logIn dateTime
DECLARE @logOut dateTime
SET @logIn = GetDate()
SELECT @IsUpdate = count(id) FROM test WHERE upper(id) = upper(@id)
IF @IsUpdate > 0
IF @logIn IS NOT NULL AND @logOut IS NULL
BEGIN
UPDATE test
SET @logOut = GetDate(), @totalHour = DATEDIFF(hour,@logIn,@logOut), @totalMinute = DATEDIFF(minute,@logIn,@logOut), @totalSecond = DATEDIFF(second,@logIn,@logOut)
END
ELSE
BEGIN
INSERT INTO test(id,logIn)
VALUES (@id,@logIn);
END
ELSE
BEGIN
INSERT INTO test(id,logIn)
VALUES (@id,@logIn);
END
RETURN
GO
|