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

StackOverflow https://stackoverflow.com/questions/22826472

Frage

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.

War es hilfreich?

Lösung

update TheNameOfYourTable
set DiffDate = DATEDIFF(days, EndDate, StartDate)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top