ZeeProgrammer
ZeeProgrammer

Reputation: 205

how to update a single column of a table with the value from the select statement that gives the date difference?

I want to update a column of a table with the value coming from the following query. SELECT DATEDIFF(days,'EndDate','StartDate') AS DiffDate. Can I do this in a single sql statement? Right now I have a table with columns(StartDate, EndDate, DiffDate) with values for StartDate and EndDate but not for DiffDate. DiffDate is null now. I am trying to update the value of DiffDate from null to the Date Difference. I appreciate the help. Thank you.

Upvotes: 0

Views: 1083

Answers (1)

Jeremy Danyow
Jeremy Danyow

Reputation: 26406

update TheNameOfYourTable
set DiffDate = DATEDIFF(days, EndDate, StartDate)

Upvotes: 2

Related Questions