Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can cast the rowversion to a bigint, then when you read the rows again you cast the column to bigint and compare against your previous stored value. The problem with this approach is the table scan each time you select based on the cast of the rowversion - This could be slow if your source table is large.</p> <p>I haven't tried a persisted computed column of this, I'd be interested to know if it works well.</p> <p>Sample code (Tested in SQL Server 2008R2):</p> <pre><code>DECLARE @TABLE TABLE ( Id INT IDENTITY(1,1) NOT NULL PRIMARY KEY, Data VARCHAR(10) NOT NULL, LastChanged ROWVERSION NOT NULL ) INSERT INTO @TABLE(Data) VALUES('Hello'), ('World') SELECT Id, Data, LastChanged, CAST(LastChanged AS BIGINT) FROM @TABLE DECLARE @Latest BIGINT = (SELECT MAX(CAST(LastChanged AS BIGINT)) FROM @TABLE) SELECT * FROM @TABLE WHERE CAST(LastChanged AS BIGINT) &gt;= @Latest </code></pre> <p>EDIT: It seems I've misunderstood, and you don't actually have a ROWVERSION column, you just mentioned row version as a concept. In that case, SQL Server Change Data Capture would be the only thing left I could think of that fits the bill: <a href="http://technet.microsoft.com/en-us/library/bb500353(v=sql.105).aspx" rel="nofollow">http://technet.microsoft.com/en-us/library/bb500353(v=sql.105).aspx</a></p> <p>Not sure if that fits your needs, as you'd need to be able to store the LSN of "the last time you looked" so you can query the CDC tables properly. It lends itself more to data loads than to typical queries.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload