Microsoft KB Archive/64559

= INF: MIN and MAX Should Not Be Used on Timestamp Column =

Article ID: 64559

Article Last Modified on 2/14/2005

-

APPLIES TO


 * Microsoft SQL Server 4.21a Standard Edition

-



This article was previously published under Q64559



MIN and MAX should not be used on timestamp columns to number rows because MIN and MAX incorrectly assume the rightmost byte is the most significant byte. Timestamps are actually incremented by assuming that the rightmost byte is the least significant byte.

After 255 updates, MIN and MAX assume the value has changed from the most positive value to the most negative value when the value really only increased by one. If a technique such as the following is used to number rows, all the rows with timestamps greater than the old timestamp of the row that crossed the 255 boundary will be skipped:

select @current=&quot;&quot;,@n=0 select @cnt=count(*) from t1  while @n<@cnt begin

select @n=@n+1 select @current=min(timestamp) from t1 where key>@current update t1 set rowcnt=@n where key=@current

Additional query words: Windows NT

Keywords: kbusage KB64559

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.