För er som som missade att få ett smakprov av kommande SQL Pass Summit 2013, …
DECLARE | — Let us declare variables: |
@count int = 0, | — Start |
@to int, | — End |
@rows int = 10; | — Rows per set |
SELECT | — Now we’re gonna |
@to = count(*) / @rows | — determe the number of sets |
FROM sys.columns | — from this table |
WHILE @count <= @to | — This loops all through to the last set |
BEGIN | |
SELECT | — Returning these |
* | — columns |
FROM sys.columns | — from this table |
ORDER BY 1 ASC | — in this order (here just based on first column). |
OFFSET (0 + (@count * @rows)) | — Based on loop we get the starting point of the offset. |
ROW FETCH NEXT (@rows) ROWS ONLY | — The number of rows we’re fetching! |
SET @count += 1 | — Next step! |
END |