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

Vra

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.

Was dit nuttig?

Oplossing

update TheNameOfYourTable
set DiffDate = DATEDIFF(days, EndDate, StartDate)
Gelisensieer onder: CC-BY-SA met toeskrywing
Nie verbonde aan StackOverflow
scroll top