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

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?
Who is Participating?
Aneesh RetnakaranConnect With a Mentor Database AdministratorCommented:
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

lthamesAuthor Commented:
Thanks!  This did exactly what I wanted.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.