update datetime column

  • how do i update the datetime column in every two or three hours from the sql.

    i want to create a job scheduler through the sql which update the datetime column in given time period like 2 hours, 3 hours etc.

  • You would update a datetime column as you would any other column. Replace whateverValueYouWantItToBe with a valid datetime value in the below code.

    UPDATE myTable

    SET myDatetimeColumn = whateverValueYouWantItToBe

    WHERE...

    Are you trying to update it to the current system time? If so you do the following...

    UPDATE myTable

    SET myDatetimeColumn = getdate()

    WHERE...

    The biggest thing is make sure you are cognizant of your where clause. Only change those records you really want to...

    You could add that as a TSQL Step in a Server Agent Job, you could then schedule the job however often you need it to occur - every 2 hours, 3very 3 or whatnot.

    -Luke.

    To help us help you read this[/url]For better help with performance problems please read this[/url]

  • thanks for the quick response.

    I want to create the program as like the system scheduler where a user has an option to enter the hours to repeat the program, so if a user place 2, then in 24 hours a day it update the column for 12 times,

    any ideas?

  • can you be a bit more verbose about what you are trying to accomplish including the number of expected users, the type of environment etc... Depending on these, there may be easier ways to do what you are attempting.

    It seems like you want to recreate all or most of the functionality that already exists within both the SA job manager and the windows scheduled tasks processes. Depending on your programming language of choice there are methods that allow you to interact with these and it may make your life a bit easier that trying to recreate the wheel.

    -Luke.

    To help us help you read this[/url]For better help with performance problems please read this[/url]

  • I still don't understand why you would do this, but you might want to look up the SQL Agent in the Books Online.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

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

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