Specifying the time criteria in a query

When querying a system-period temporal table, you can include FOR SYSTEM_TIME in the FROM clause to query the current and past state of your data.

Time periods can be specified in three ways:

  • AS OF value

    Includes each row for which the row-begin value is less than or equal to value and the row-end value is greater than value. Zero rows are returned if value is the null value.

  • FROM value1 TO value2

    Includes rows that exist completely within the period that is specified from value1 up to value2. A row is included if the row-begin value is less than value2 and the row-end value is greater than value1. Zero rows are returned if value1 is greater than or equal to value2 or if value1 or value2 is the null value.

  • BETWEEN value1 AND value2

    Includes rows that overlap at any point in time between value1 and value2. A row is included if its row-begin value is less than or equal to value2 and the row-end value is greater than value1. Zero rows are returned if value1 is greater than value2 or if value1 or value2 is the null value. If value1 = value2, the expression is equivalent to AS OF value1.

For detailed information about time periods, see table-reference and Queries.