Search code examples
sql-servertemporal-tables

Temporal Tables Between Clause - Rows are included that shouldn't be?


I have a SQL Server 2016 temporal table. I executed a query which can be seen below, along with the results. I'm curious why the row highlighted in green is included. The ValidFrom value occurs before the begin date of '7/12/2018 19:16:00' and the ValidTo occurs after the end date of '7/12/2018 19:30:00'.

My understanding of BETWEEN / AND, which might be incorrect, is that it finds all rows modified between two points in time.

enter image description here


Solution

  • The BETWEEN clause on a temporal table shows those rows that were active during the selected timeframe. In more conventional terms, the rows that meet this criteria set:

    WHERE StartTime <= <EndDateTime> 
        AND EndTime > <StartDateTime>
    

    As you can see, this does not require an actual time stamp to fall within your BETWEEN dates.