Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
| Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 21st, 2008, 11:06 AM
Authorized User
 
Join Date: Dec 2005
Location: , Colorado, USA.
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rdove84
Default 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


 
Old January 22nd, 2008, 12:32 AM
Friend of Wrox
 
Join Date: Oct 2007
Location: , , .
Posts: 130
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via AIM to urtrivedi
Default

I think you have not initialised logouttime. before using it

urt




Similar Threads
Thread Thread Starter Forum Replies Last Post
Stored Procedure muthu555 SQL Server 2000 1 March 5th, 2007 07:13 AM
Calling on a database within a stored procedure Hadware SQL Language 1 January 8th, 2007 05:11 PM
Stored Procedure bmains SQL Server ASP 2 October 8th, 2004 03:19 AM
Stored Procedure to.... flyin ADO.NET 3 March 3rd, 2004 02:01 AM
C# and stored procedure Msmsn C# 1 August 26th, 2003 11:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.