Home > Software engineering >  How to query a system versioned table for recent changes?
How to query a system versioned table for recent changes?

Time:11-04

Clearly my understanding of the semantics of system versioned tables is wrong. I've tried a few things without success. Eg "between" and "contained in".

I have a system versioned table with a date column. It has the date that a record was inserted. But I want to query to get all records that were inserted or changed in the last 10 minutes, and so want to make use of the fact that this is a system versioned table. But I can't figure out the right way to formulate this query.

CodePudding user response:

You would do as you would for querying any table with a datetime2 column, for example you could do

select * from table
for system_time all
where SysValidFrom >= DateAdd(minute,-10,GetDate())

Note that SysValidFrom is the name of the system-versioned valid-from date - your column naming convention may vary.

  • Related