Query changed records in SQL using a created / modified time stamp column?

时间:2016-07-11 23:11:07

标签: sql sql-server

I'm trying to query my SQL Server 2008 R2 database to find out records that were put into a cancelled state during a given time period. Each record consist of one row in the database with a Created By timestamp, and a modified by timestamp. I can't change the schema of the database.

Each record has a "cancel state" column that is set to 0 or 1 (N and Y). I need to run a nightly job/query that will show all of the cancelled records from the day.

Simple enough, when the record is cancelled the modified timestamp is updated, so my query looks like

 SELECT * 
 FROM mytable 
 WHERE CONVERT(DATE, a.modified_timestamp) = CONVERT(DATE, CURRENT_TIMESTAMP) 
   AND cancel_flag = '1'

The issue I am running into, if any other data is modified in the record, the timestamp is updated so the query will give me duplicate results if some other value in the row is changed. Is there an easy way to do this without changing the schema or adding my own table for tracking?

0 个答案:

没有答案