If Statement is not working

  • If Statement is not working

    IF (@max-@min)>290

    BEGIN

    SELECT @col3 = SUM(Latin) FROM allcount;

    DELETE FROM allcount;

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

    END;

    END;

  • Here is my whole program. Before the If works fine.

    CREATE PROCEDURE [IncCondense] (@datetime DATETIME, @latin INT) AS

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

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

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

    IF (@max-@min)>290

    BEGIN

    SELECT @col3 = SUM(Latin) FROM allcount;

    DELETE FROM allcount;

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

    END;

    END;

    GO

  • You have 1 BEGIN and 2 END.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Check your max - min is actually > 290:

    SELECT @max-2,@min, @max-@min

    You have no else statement

    Also it looks to me like you have an extra "end" at the end

    Are you getting any kind of errors?

    Hope that helps

  • I took out one end; and it still does not work.

  • Define "does not work". Are you getting an error? What should it do and it's not doing? Or what is it doing that it shouldn't?

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 6 posts - 1 through 5 (of 5 total)

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