How can I build a query to update records in sql server 2008 with the current date/time

Posted on 2009-05-01
Last Modified: 2012-05-06
I have a table with Task_ID, User_ID, StartTime, and EndTime

My app is writeen in VB6 and I use adodb to connect to the sql server.

I need an update query (that will be turned into a stored procedure)  that accepts a User_ID and then updates 'NOW' to the EndTime for every record for that User_ID that has 'null' in the EndTime.

I could also pass the current time to the query if needed.

But how would I go about writing the query and the stored procedure to accomplish this?
Question by:lthames
    LVL 75

    Accepted Solution

    create procedure updateEndTime
    @User_id int,
    @Now datetime = null
      UPDATE urTable
      SET EndTime  = ISNULL(@now, GETDATE() )
      WHERE User_ID = @User_id and EndTime IS NULL


    Author Closing Comment

    Thanks!  This did exactly what I wanted.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now