user3614477
user3614477

Reputation: 25

DateDiff for every row?

I have two Columns

Move In Date                     Move Out Date
2/24/2011                         2/25/2014

I have similar data for 20,000 rows. I want another column

Length of Stay

(Difference between MoveOutDate and MoveIn Date) only in Years.

but I need the query to run for every row in the table.

How can I do this?

Upvotes: 0

Views: 293

Answers (2)

Vignesh Kumar A
Vignesh Kumar A

Reputation: 28403

Try this

SELECT MoveInDate,MoveOutDate,DATEDIFF(year,MoveInDate,MoveOutDate) As Years
FROM Table1

DateDiff

Upvotes: 1

MayOkba
MayOkba

Reputation: 99

select Move_In_Date,Move_Out_Date,datediff(year,Move_In_Date,Move_Out_Date) as year_diff
from yourTable

Upvotes: 1

Related Questions