title: Calculating Days Between Dates in Separate Rows For Same UnitID
body: <p>I am trying to calculate the time a commercial real estate space sits vacant.  I have move-in &amp; move-out dates for each tenant that has occupied that unit.  It is easy to calculate the occupied time of each tenant as that data is within the same row.  However, I want to calculate the vacant time: the time between move-out of the previous tenant and move-in of the next tenant.  These dates appear in separate rows.</p>
  <p>Here is a sample of what I have currently:</p>
  <pre><code>SELECT 
      uni_vch_UnitNo AS UnitNumber, 
      uty_vch_Code AS UnitCode, 
      uty_int_Id AS UnitID,  tul_int_FacilityId AS FacilityID, 
      tul_dtm_MoveInDate AS Move_In_Date, 
      tul_dtm_MoveOutDate AS Move_Out_Date, 
      DATEDIFF(day, tul_dtm_MoveInDate, tul_dtm_MoveOutDate) AS Occupancy_Days
  FROM TenantUnitLeases
  JOIN units
      ON tul_int_UnitId = uni_int_UnitId
  JOIN UnitTypes
      ON uni_int_UnitTypeId = uty_int_Id
  WHERE 
      tul_int_UnitId = '26490'
  ORDER BY tul_dtm_MoveInDate ASC
  </code></pre>
  <p><a href="https://i.stack.imgur.com/54VyN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/54VyN.png" alt="enter image description here" /></a></p>
  <p>Is there a way to assign an id to each row in chronological, sequential order and find the difference between row 2 move-in date less row 1 move-out date and so on?</p>
  <p>Thank you in advance for the help.</p>