Declare statement

  • I had a following query

    "DECLARE @i int, @cnt INT, @ERRMSG VARCHAR(200),

    SET @i=0

    IF (SELECT count(*) FROM alarms WHERE mode = 'production' and sentflag != '200') >50

    BEGIN

    WHILE @i< 3

    BEGIN

    WAITFOR DELAY '00:03:00'

    SET @cnt=(SELECT count(*) FROM alarms WHERE mode = 'production' and sentflag != '200')

    SET @i=@i+1

    END

    IF @cnt >50

    BEGIN

    SET @ERRMSG= 'Alarms are not forwading to Socadmin,check the AlertLoad task SQL job OR Alarm table for failed alerts'

    RAISERROR (@ERRMSG, 16, 1) WITH LOG

    END

    END"

    In this query i need to set time for 15 minutes instead of having count value(cnt) greater than 50,can anyone please suggest some changes in this script,the aim of this script is to alert according to the alarm count?

    Thanks,in advance

  • 15 minutes in what context?

    Table definitions please. Hard to tell what's going on 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 1 (of 1 total)

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