Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

T sql script to alter SQL Server agent job if exists

Posted on 2014-01-12
6
Medium Priority
?
2,549 Views
Last Modified: 2014-01-27
Hi Experts,

  Could you please help me with T-Sql script to alter SQL Server agent job.  If the job exists, then I need to alter the job script ,to  add more steps and also edit the existing steps.  
I don't want to add it manually through wizard as we want to run the T-Sql scripts only (as we don't have access to production environments)

I need a sample Alter script . Your help is greatly appreciated in this regard.

Please Note : I don't want to drop and create the existing job in production as I would loose history of the job.

Regards,

Sreekanth.
0
Comment
Question by:n_srikanth4
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 39775430
I would go through the steps with the wizard, just don't finish and instead save the SQL Scripts off so that you can optionally edit them and have them ultimately run in Production.

Let me know if you need help with that.
0
 

Author Comment

by:n_srikanth4
ID: 39775464
Hi Savant ,

     I could not go through the wizard , It will just add the step , but not generate any script .  Secondly , the  jobs are already created in Dev server , so i cannot undo the wizard.  So could you please walk through an example sample script please.

Regards,

Srk.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 39775503
i would drop the step in development and start again using the wizard, but this time save the SQL scripts, before you finish.

P.S.  The name is Anthony (you will see it as it is just below where it says "Your Comment" and after "by:")
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 38

Accepted Solution

by:
Jim P. earned 1500 total points
ID: 39775517
My suggestion is that you create your own "history" table that you write the results to as the steps run. Basically as the first part of that particular step you insert the step name, time, server, db and other details at the beginning into the history table. Then at the end of the step you have a similar insert statement.

That way you aren't dependent on the job history table.

Then adding steps or replacing the script you don't lose the history. And if you build out the script for more stuff, you can just hand it off to the production team and move on.
0
 
LVL 35

Expert Comment

by:David Todd
ID: 39781034
Hi,

If you examine the script of the existing job, that script should have all the clues you need. That is, the job steps are added to the job one at a time. Of course you'll have to add logic that finds how many existing steps there are, and appends them. And don't forget to modify existing last step to go on to the next on success.

HTH
  David
0
 

Author Closing Comment

by:n_srikanth4
ID: 39813554
good
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question