tsql - Return row of every n'th record -


how can return every nth record sub query based on numerical parameter supply?

for example, may have following query:

select    id,    key datatable customerid = 1234 order key 

e.g.

the subquery result may following:

row id   key 1   1    a3231 2   43   c1212 3   243  e1232 4   765  g1232 5   2432 e2325 ... 90  3193 f2312 

if pass in number 30, , sub query result set contained 90 records, recieve 30th, 60th, , 90th row.

if pass in number 40, , result set contained 90 records, recieve 40th , 80th row.

as side note, background information, being used capture key/id of every nth record paging control.

this row_number can help. requires order-by clause okay because order-by present (and required guarantee particular order).

select t.id, t.key (     select id, key, row_number() on (order key) rownum     datatable ) t t.rownum % 30 = 0    -- or % 40 etc order t.key 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -