Automating job scripts

  • What I want to do is create some stored procedures where I pass e.g. a database name and use that in the stored procedure to generate the required SQL job / alert / backup devices etc.

    For example, I want to

    1 - pass a variable @name to a select statement to find a job id from sysjobs table.

    2 - assign the job id to a variable.

    3 - variable in create statement - eg and create alert statement to define the variable as the value for (in this example) the alert response job.

    the problem is I get - variable .... not defined as a scalar value.

    I'm not sure why I get that error?

    Is what I want to do possible?

    _____________________________________________________________________________MCITP: Business Intelligence Developer (2005)

  • dave-dj (6/3/2010)


    the problem is I get - variable .... not defined as a scalar value.

    post your script

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • Job_ID is not an int. You have to use uniqueidentifier or char / varchar data types for your variable.

    EDIT: And yes, what you want to do is possible. Just adjust your expectations of how to deal with the data type and your code should work.

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

  • guys,

    thanks for posting - I think i've now found the cause of the problem which seemed related to how I set the variable.

    _____________________________________________________________________________MCITP: Business Intelligence Developer (2005)

  • Glad we could help. Let us know if you need anything else.

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

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

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