SQL Jobs help

  • I want to write a scheduled job for my database to run every night.

    Essentially I need the job to match todays date in the database and then add 1500 to an existing number in the results table.

    Is a job the correct way to go about this? If so how to do?

    There's is lot's of tutorials on setting up the job and schedule, but not so much help on the writing the procedures within.

    I'm not a newbie with regards to stored procedures, but definitely new to jobs.

    Helps please.

    thanks

  • dean 62842 (1/26/2010)


    I want to write a scheduled job for my database to run every night.

    Essentially I need the job to match todays date in the database and then add 1500 to an existing number in the results table.

    Is a job the correct way to go about this? If so how to do?

    I am not sure if there is any better way of doing it. THere could be.. lets wait and see if someone has a better idea.

    There's is lot's of tutorials on setting up the job and schedule, but not so much help on the writing the procedures within.

    I'm not a newbie with regards to stored procedures, but definitely new to jobs.

    Jobs -> New Job -> enter general details -> Go to steps tab -> Click on 'New' -> Enter the step Name -> Select type as 'Transact -SQL script (T-SQL)' -> Select the database -> just Enter the sp name in the command window -> parse -> ok->Schedules -> enter schedules-> ok

    Your stored procedure would contain the code along these lines..

    UPDATE UT

    SET sale = Sale + 1500 -- Select *

    FROM ABC UT

    WHERE dateadd(dd, 0, Datediff(dd, 0, date1)) =

    dateadd(dd, 0, Datediff(dd, 0, Getdate()))

    hope this helps!

    ---------------------------------------------------------------------------------

  • A job is the easiest way to do it, but not the only way. You could setup a service broker queue to run the proc every night at the same time. You could setup an infinite loop proc that only executes the stores procedure when you want it.

    However, for what you are looking for, a job is probably the easiest and most efficient way to do it.

    Nabha hit the nail on the head for the rest of it.

    Fraggle

  • Wow guys!

    Thanks to both for the very prompt reply.

    This has given me exactly what I needed.

    Thank You

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

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