SQL Job with IF Criteria

  • I would like to create a job for

    SELECT datediff(n, dc_date ,last_start_date) FROM PARM

    if the output is more than 10 mins i would like to send an email.

    I looked into creating a SQL job but there is no place where i can specify IF statement for the output from SQL Statement.

  • Well yes you can.

    If ()

    begin

    sp_send_dbmail

    end

    Schedule that to run every x minutes and you're on your way.

  • i'd code it with an EXISTS like this:

    IF EXISTS(SELECT 1

    FROM PARM

    WHERE datediff(n, dc_date ,last_start_date) > 10)

    BEGIN

    --do stuff here

    PRINT 'Sending emails'

    END

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

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

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