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

Domanda

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.

È stato utile?

Soluzione

update TheNameOfYourTable
set DiffDate = DATEDIFF(days, EndDate, StartDate)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top