Usage of T-SQL script in SQL server Agent jobs

  • I am using a T-SQL script in my job and i want to move to the next step based on the result of my T-SQL script. Is there any option by which i can do this . I do not want to use a package having Eecute SQL task in my job.

  • What is that your doing in TSQL Steps? Can you able to return any return global variable from that TSQL?

  • Don't think there is a job option to do this. You could try managing it through a process table that each step would update and validate against.

    Ex.

    Job Step 1

    - does some work then updates t_progress

    Job Step 2

    - checks t_progress

    - if appropriate: does some work then updates t_progress

    - if not appropriate: skip some work

    Job Step 3

    - checks t_progress

    - if appropriate: does some work then updates t_progress

    - if not appropriate: skip some work

    etc.

    _____________________________________________________________________
    - Nate

    @nate_hughes
  • yes, iam taking a count and if that count is greater than 0 iam returning

    result=1 and if it is not than result =0.

    But i am not able to run my job according to the job condition result.

  • Insert the count into a table, and then execute the next step based upon what is in the table.

  • You could simply use the "success" or "failure" options in the job definition to define branching.

    It would look something like:

    Step 1: do something for real

    Step 2 (branching step)

    do your count. The step would look something like this:

    Declare @count int

    set @count=count(*) from MyTable

    where MyCriteria='True'

    If @count>0

    Raiserror('We are branching down the "failure" line now',16,1)

    This will cause this step to fail if the count is >0.

    You can then use the advanced settings to decide what to do then.....

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • What if the first step is a T-SQL and second step is a CMD ?

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

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