Create Sql Job

  • Hello All

    i would like to create a sql job which execute my define code per minute but it's not working properly

    when i shutdown my PC,and on next day i start my pc the next start day will forward to 3 days

    please help me out i use following code

    USE msdb ;

    EXEC dbo.sp_add_job

    @job_name = N'ExecuteGreedyTran',

    @enabled = 1,

    @description = N'Execute transactions in per one min'

    exec sp_add_jobschedule

    @job_name =N'ExecuteGreedyTran',

    @name = N'ExecuteGreedyTran',

    @freq_type =4,@freq_interval =4,

    @freq_subday_type =0x4,@freq_subday_interval=1,@active_start_date =20090821,

    @active_end_date =20091228,

    @active_start_time =091400

    EXEC sp_add_jobstep

    @job_name = N'ExecuteGreedyTran',

    @step_name = N'ExecuteGreedyTran',

    @subsystem = N'TSQL',

    @command = N'USE test insert into ztest values (1,''1 job'',''2 job'')',

    @retry_attempts = 5,

    @retry_interval = 5 ;

    GO

    exec sp_add_jobserver @job_name = 'ExecuteGreedyTran'

  • What's not working properly? when you reboot it is set to start 3 days from the boot?

  • yes sir that's my problem

  • Occurs every 4 day(s) every 1 minute(s) between 09:14:00 and 23:59:59. Schedule will be used between 21/08/2009 and 28/12/2009.

    you need to change it to

    Occurs every day every 1 minute(s) between 09:14:00 and 23:59:59. Schedule will be used between 21/08/2009 and 28/12/2009.

    view the job schedule properties and change the recurs every:

    from 4 days

    to 1 days

    --------------------------------------------------------------------------------------
    [highlight]Recommended Articles on How to help us help you and[/highlight]
    [highlight]solve commonly asked questions[/highlight]

    Forum Etiquette: How to post data/code on a forum to get the best help by Jeff Moden[/url]
    Managing Transaction Logs by Gail Shaw[/url]
    How to post Performance problems by Gail Shaw[/url]
    Help, my database is corrupt. Now what? by Gail Shaw[/url]

  • on another note, if you want it to work only on a working week.

    change it to weekly and just select the days that you want it to run on.

    --------------------------------------------------------------------------------------
    [highlight]Recommended Articles on How to help us help you and[/highlight]
    [highlight]solve commonly asked questions[/highlight]

    Forum Etiquette: How to post data/code on a forum to get the best help by Jeff Moden[/url]
    Managing Transaction Logs by Gail Shaw[/url]
    How to post Performance problems by Gail Shaw[/url]
    Help, my database is corrupt. Now what? by Gail Shaw[/url]

  • Any one help me

    how can i do that using Code

    i am not well aware about interface

    please tell what am i doing wrong

    Thanks

    mahendra singh rajpurohit

  • Replace your code in sp_add_jobschedule with the following. I think it would work.

    @freq_type=4,

    @freq_interval=1,

    @freq_subday_type=4,

    @freq_subday_interval=1,

    @freq_relative_interval=0,

    @freq_recurrence_factor=1,

  • This will fix it for you, before I get shouted at for using a deprecated command, I know it is sql 2000, but it works.

    sp_update_jobschedule @job_Name= 'ExecuteGreedyTran',@Name= 'ExecuteGreedyTran', @freq_interval = 1

    --------------------------------------------------------------------------------------
    [highlight]Recommended Articles on How to help us help you and[/highlight]
    [highlight]solve commonly asked questions[/highlight]

    Forum Etiquette: How to post data/code on a forum to get the best help by Jeff Moden[/url]
    Managing Transaction Logs by Gail Shaw[/url]
    How to post Performance problems by Gail Shaw[/url]
    Help, my database is corrupt. Now what? by Gail Shaw[/url]

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

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