[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 140
  • Last Modified:

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?
0
lthames
Asked:
lthames
1 Solution
 
Aneesh RetnakaranDatabase AdministratorCommented:
create procedure updateEndTime
@User_id int,
@Now datetime = null
AS
BEGIN
  SET NOCOUNT ON
  UPDATE urTable
  SET EndTime  = ISNULL(@now, GETDATE() )
  WHERE User_ID = @User_id and EndTime IS NULL

END
0
 
lthamesAuthor Commented:
Thanks!  This did exactly what I wanted.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now