473,805 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing schedules for a Job outside SQL Server

Below is the script of a Job called "eFIMS_SendEmai l" that I wish to
run. The intention is that every day of the week the job will execute
a SPROC at timed intervals. For example, the SundayRun schedule will
run once every 1 hours from 00:30:00 to 23:59:59

However, the clients have stated that they want an interface to this to
enable them easily to change the start time and frequency interval for
each day. It's an easy matter for me to paint them a form from within
the target application to enable the user to enter the start time and
interval for each day. I can then pass these as parameters to a SPROC.
How can I use these values to change the schedules for the job? For
example, if wanted to change SundayRun from once every 1 hours to once
every 30 mins? I know I could do it the hard way, by using string
manipulation (e.g. find string 'SundayRun', then look for the next
occurrence of @active_start_t ime, @freq_subday_ty pe,
@freq_subday_in terval etc. and do some replacement) but this seems
somewhat tricky.

Many thanks

Edward

-- Script generated on 8/31/2006 9:27 AM
-- By: sa
-- Server: BISMARK

BEGIN TRANSACTION
DECLARE @JobID BINARY(16)
DECLARE @ReturnCode INT
SELECT @ReturnCode = 0
IF (SELECT COUNT(*) FROM msdb.dbo.syscat egories WHERE name =
N'[Uncategorized (Local)]') < 1
EXECUTE msdb.dbo.sp_add _category @name = N'[Uncategorized (Local)]'

-- Delete the job with the same name (if it exists)
SELECT @JobID = job_id
FROM msdb.dbo.sysjob s
WHERE (name = N'eFIMS_SendEma il')
IF (@JobID IS NOT NULL)
BEGIN
-- Check if the job is a multi-server job
IF (EXISTS (SELECT *
FROM msdb.dbo.sysjob servers
WHERE (job_id = @JobID) AND (server_id <0)))
BEGIN
-- There is, so abort the script
RAISERROR (N'Unable to import job ''eFIMS_SendEma il'' since there
is already a multi-server job with this name.', 16, 1)
GOTO QuitWithRollbac k
END
ELSE
-- Delete the [local] job
EXECUTE msdb.dbo.sp_del ete_job @job_name = N'eFIMS_SendEma il'
SELECT @JobID = NULL
END

BEGIN

-- Add the job
EXECUTE @ReturnCode = msdb.dbo.sp_add _job @job_id = @JobID OUTPUT ,
@job_name = N'eFIMS_SendEma il', @owner_login_na me = N'sa', @description
= N'No description available.', @category_name = N'[Uncategorized
(Local)]', @enabled = 0, @notify_level_e mail = 0, @notify_level_p age =
0, @notify_level_n etsend = 0, @notify_level_e ventlog = 2,
@delete_level= 0
IF (@@ERROR <0 OR @ReturnCode <0) GOTO QuitWithRollbac k

-- Add the job steps
EXECUTE @ReturnCode = msdb.dbo.sp_add _jobstep @job_id = @JobID,
@step_id = 1, @step_name = N'SendEmail', @command = N'EXEC
stpSendEmailCon firmation', @database_name = N'194-eFIMS', @server =
N'', @database_user_ name = N'', @subsystem = N'TSQL',
@cmdexec_succes s_code = 0, @flags = 4, @retry_attempts = 0,
@retry_interval = 1, @output_file_na me = N'', @on_success_ste p_id = 0,
@on_success_act ion = 1, @on_fail_step_i d = 0, @on_fail_action = 2
IF (@@ERROR <0 OR @ReturnCode <0) GOTO QuitWithRollbac k
EXECUTE @ReturnCode = msdb.dbo.sp_upd ate_job @job_id = @JobID,
@start_step_id = 1

IF (@@ERROR <0 OR @ReturnCode <0) GOTO QuitWithRollbac k

-- Add the job schedules
EXECUTE @ReturnCode = msdb.dbo.sp_add _jobschedule @job_id = @JobID,
@name = N'SundayRun', @enabled = 1, @freq_type = 8, @active_start_d ate
= 20060831, @active_start_t ime = 3000, @freq_interval = 1,
@freq_subday_ty pe = 8, @freq_subday_in terval = 1,
@freq_relative_ interval = 0, @freq_recurrenc e_factor = 1,
@active_end_dat e = 99991231, @active_end_tim e = 235959
IF (@@ERROR <0 OR @ReturnCode <0) GOTO QuitWithRollbac k
EXECUTE @ReturnCode = msdb.dbo.sp_add _jobschedule @job_id = @JobID,
@name = N'MondayRun', @enabled = 1, @freq_type = 8, @active_start_d ate
= 20060831, @active_start_t ime = 3000, @freq_interval = 2,
@freq_subday_ty pe = 4, @freq_subday_in terval = 30,
@freq_relative_ interval = 0, @freq_recurrenc e_factor = 1,
@active_end_dat e = 99991231, @active_end_tim e = 235959
IF (@@ERROR <0 OR @ReturnCode <0) GOTO QuitWithRollbac k
EXECUTE @ReturnCode = msdb.dbo.sp_add _jobschedule @job_id = @JobID,
@name = N'TuesdayRun', @enabled = 1, @freq_type = 8, @active_start_d ate
= 20060831, @active_start_t ime = 4000, @freq_interval = 4,
@freq_subday_ty pe = 4, @freq_subday_in terval = 40,
@freq_relative_ interval = 0, @freq_recurrenc e_factor = 1,
@active_end_dat e = 99991231, @active_end_tim e = 235959
IF (@@ERROR <0 OR @ReturnCode <0) GOTO QuitWithRollbac k
EXECUTE @ReturnCode = msdb.dbo.sp_add _jobschedule @job_id = @JobID,
@name = N'WednesdayRun' , @enabled = 1, @freq_type = 8,
@active_start_d ate = 20060830, @active_start_t ime = 3000,
@freq_interval = 8, @freq_subday_ty pe = 4, @freq_subday_in terval = 30,
@freq_relative_ interval = 0, @freq_recurrenc e_factor = 1,
@active_end_dat e = 99991231, @active_end_tim e = 235959
IF (@@ERROR <0 OR @ReturnCode <0) GOTO QuitWithRollbac k
EXECUTE @ReturnCode = msdb.dbo.sp_add _jobschedule @job_id = @JobID,
@name = N'ThursdayRun', @enabled = 1, @freq_type = 8,
@active_start_d ate = 20060831, @active_start_t ime = 3500,
@freq_interval = 16, @freq_subday_ty pe = 4, @freq_subday_in terval = 35,
@freq_relative_ interval = 0, @freq_recurrenc e_factor = 1,
@active_end_dat e = 99991231, @active_end_tim e = 235959
IF (@@ERROR <0 OR @ReturnCode <0) GOTO QuitWithRollbac k
EXECUTE @ReturnCode = msdb.dbo.sp_add _jobschedule @job_id = @JobID,
@name = N'FridayRun', @enabled = 1, @freq_type = 8, @active_start_d ate
= 20060831, @active_start_t ime = 3000, @freq_interval = 32,
@freq_subday_ty pe = 4, @freq_subday_in terval = 30,
@freq_relative_ interval = 0, @freq_recurrenc e_factor = 1,
@active_end_dat e = 99991231, @active_end_tim e = 235959
IF (@@ERROR <0 OR @ReturnCode <0) GOTO QuitWithRollbac k
EXECUTE @ReturnCode = msdb.dbo.sp_add _jobschedule @job_id = @JobID,
@name = N'SaturdayRun', @enabled = 1, @freq_type = 8,
@active_start_d ate = 20060831, @active_start_t ime = 0, @freq_interval =
64, @freq_subday_ty pe = 8, @freq_subday_in terval = 1,
@freq_relative_ interval = 0, @freq_recurrenc e_factor = 1,
@active_end_dat e = 99991231, @active_end_tim e = 235959
IF (@@ERROR <0 OR @ReturnCode <0) GOTO QuitWithRollbac k

-- Add the Target Servers
EXECUTE @ReturnCode = msdb.dbo.sp_add _jobserver @job_id = @JobID,
@server_name = N'(local)'
IF (@@ERROR <0 OR @ReturnCode <0) GOTO QuitWithRollbac k

END
COMMIT TRANSACTION
GOTO EndSave
QuitWithRollbac k:
IF (@@TRANCOUNT 0) ROLLBACK TRANSACTION
EndSave:

Aug 31 '06 #1
1 5723

te********@hotm ail.com wrote:

Repeat after me - "Look in BOL before posting; Look in BOL before
posting"

- sorry to waste all your time!

Edward

Aug 31 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2509
by: Emanuel Marciniak | last post by:
Hi all, We have the form which uses checkboxes for several fields and the target action points to outside webservice. Unfortunatelly they do not support checkboxes. How to pass it as a radio buttons or pull down select box with Yes/No options for example (which they support) using still checkboxes as an input entry. Thank you for any hint, emanuel
1
2116
by: Ken Fine | last post by:
I have a menu system that has nodes that can be opened or closed. In an effort to make my code more manageable, I programmed a little widget tonight that keeps track of the open/active item and automatically builds querystrings for my redirect URLS. The code for this follows. It defines an ASP Dictionary object, and key/value pairs for each, and builds appropriate querystrings based on comparison with a status variable. The way it works...
2
2786
by: Rajesh Kapur | last post by:
Hello, We use Informix and MySQL on linux/unix to drive our web application. SQL*Server is used only for backend enterprise applications within the firewall. I am trying to get the management to use SQL*Server outside the firewall. They tell me there are security issues with Microsoft products, including SQL*Server, that make it vulnerable to attacks outside the firewall. Can someone please point me to white papers/documentation that...
3
2138
by: Geoff Matthews | last post by:
I apologize for the basic question, but MS's documentation has been no help at all. I'm working on a database, and need to create a form for schedules, M-F, 8-4. I've settled on an easy way out, by creating 5 similar tables (Monday, Tuesday, Wednesday, etc.) with the same fields (8, 9, 10, etc.) that link up to one table (Schedule) and then to the person. Not elegant, but I'm beginner. I've tried to design a form from scratch,...
3
2304
by: mark | last post by:
HELP!!! Last week we moved the Server From 1 Location to Another that was running Replication Manager 4.0. (We changed the IP Addresses and changed the name servers also... ) After the switchover, everyone that is outside our Local Area Network is unable to get a successful sync. I've checked all the settings that I know and everything looks right - The Drop Box is getting data from the outside and It looks like the Managed Databases are...
5
1454
by: T. Wong | last post by:
I want to have a single CSS style sheet control the look of my whole asp.net application but I need to set the values in this CSS from code in the start page as the CSS values will be stored in a data base. First, is this possible? Since CSS is plain text I could manipulate it all with string string functions in code, BUT, are there any classes or functions that make it easier to affect CSS parameters at run time?
3
2315
by: mosscliffe | last post by:
I need to reference a file on my published server as "../mydir/myfile.txt", which is fine and it works. On my local develop computer the "../mydir" refers to C:\Program Files\Microsoft Visual Studio 8\Common7 Is there any way I can get the "../" to refer to somewhere more convenient, ideally as /mydir within my project. I could not find any settings in Visual Studio, which referred to this
2
5694
by: mj.redfox.mj | last post by:
Hi, I wonder if someone could possibly help with this? I have the following code, which is a nested repeater in turn nesting a datalist. This all works fine, together with my page-behind vb code controlling the relations etc. Now, what I'm wanting to do is to call a subroutine 'subroutine1' when the repeater is data bound, which I'm wanting to use to change the background colour of table cell tdCell1 depending on the value of
11
2510
by: =?Utf-8?B?UGF1bA==?= | last post by:
I did a google search but could find what I was looking for. I am creating a temporary folder and placing files in it with a web application. The temporary folder name needs to be changed dynamically by the program, leaving all the files in the folder. Just wondering if anyone has done this? thanks. -- Paul G Software engineer.
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10609
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10360
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10105
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4323
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.