var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: return the value of the 5000th record in iteration
I want an elegant way to retrieve each iteration of the value of the 5000th record from a table with a clustered PK int column name: ID
so the 5000th, 10000th, 15000th, etc... until as many records in the table
-- for example this will get me the 1st
SELECT TOP 1 Q1.Id FROM
SELECT TOP 5000 Id FROM myTable T
ORDER BY T.Id
ORDER BY Q1.Id DESC
Last edited by Gagnon; 10-11-10 at 17:52.
I figured it out:
; WITH OrderedIds AS
ROW_NUMBER() OVER (ORDER BY Id) AS 'RowNumber'
WHERE RowNumber % 5000 = 0;
Elegant and simple solution. Nice.
With kind regards . . . . . SQL Server 2000/2005/2012
Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages