Working If Statement

  • A working if statement is needed.

    CREATE PROCEDURE [IncCondense] (@latin INT) AS

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

    SET @datetime = Getdate();

    SELECT @datetime;

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

    SELECT @min-2=MIN(ida), @max-2=MAX(ida) FROM allcount;

    IF (@max-@min)>200

    SELECT @col3 = SUM(Latin) FROM allcount;

    DELETE FROM allcount;

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

  • Read about BEGIN in books online. Which statements do you expect to be executed when IF returns true?


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • CREATE PROCEDURE [IncCondense] ( @latin INT )

    AS

    BEGIN

    DECLARE @max-2 INT

    , @min-2 INT

    , @col3 INT

    , @datetime DATETIME;

    SET @datetime = GETDATE();

    SELECT @datetime;

    INSERT INTO allcount ( datetime, Latin )

    VALUES ( @datetime, @latin )

    SELECT @min-2 = MIN(ida)

    , @max-2 = MAX(ida)

    FROM allcount;

    IF ( @max-2 - @min-2 ) > 200

    BEGIN

    SELECT @col3 = SUM(Latin)

    FROM allcount;

    DELETE FROM allcount;

    INSERT INTO allcount ( datetime, Latin )

    VALUES ( @datetime, @col3 );

    END

    END

    GO

    Something like this I would guess.

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

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