日期:2014-05-16 浏览次数:20901 次
use pubs declare @fid int declare @milestone int declare @count int declare @val int set @fid = 1 set @milestone = 1 truncate table milestone --得到总的milestone数 select @count = count(1) / 10000 from thread where fid = @fid --第一个milestone select top 1 @val = lastpost from thread with ( nolock ) where fid = @fid and lastpost not in ( select top 10000 lastpost from thread with ( nolock ) where fid = @fid order by lastpost desc ) order by lastpost desc insert into milestone ( fid, milestone, lastpostdesc ) values ( @fid, @milestone, @val ) set @milestone = @milestone + 1 while ( @milestone <= @count ) begin select top 1 @val = lastpost from thread with ( nolock ) where fid = @fid and lastpost < @val and lastpost not in ( select top 10000 lastpost from thread with ( nolock ) where fid = @fid and lastpost < @val order by lastpost desc ) order by lastpost desc insert into milestone ( fid, milestone, lastpostdesc ) values ( @fid, @milestone, @val ) set @milestone = @milestone + 1 end