Condense the database to one line with the sum of the column

  • For the datetime I am trying to CONVERT the date and time in the form:

    yyyy-mm-dd hh:mm:ss

    The time is in 24hour time.

    Then I insert it into the database.

    I find the maximum and the minimum values in my primary key.

    If the difference of the max-min if greater than 1000

    it will condense the database to one line with the sum of the column "Latin" into one cell.

    Could you please check my work.

    CREATE PROCEDURE [IncMaxallcount] (@Latin INT) AS

    DECLARE @max INT, @min INT, @col3 INT,@datetime DATETIME;

    SET @datetime = Getdate();

    CONVERT (@datetime , 120);

    INSERT INTO allcount (datetime,Latin) VALUES (@datetime,@Latin)

    SELECT

    @min=MIN(ida)

    ,@max=MAX(ida)

    FROM allcount;

    IF (@max-@min)>1000

    BEGIN

    SELECT

    @col3 = SUM(Latin)

    FROM allcount;

    DELETE FROM allcount;

    INSERT INTO allcount (datetime, Latin) VALUES (@datetime,@col3);

    END;--IF

    END;--PROC

    GO

  • Have you tried the code?

    If so, does it do what you expect?

    If not, what does it not do (or what error does it throw)?

    Edit: Duplicate thread, please rather continue at http://www.sqlservercentral.com/Forums/Topic1535267-391-1.aspx not here.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply