Skip to content

fix(sqlserver): use ROW_NUMBER pagination for SQL Server < 2012 (#1693) - #1919

Merged
Chat2DB-Pro merged 1 commit into
OtterMind:mainfrom
HandSonic:fix/1693-mssql-pagination
Jul 21, 2026
Merged

fix(sqlserver): use ROW_NUMBER pagination for SQL Server < 2012 (#1693)#1919
Chat2DB-Pro merged 1 commit into
OtterMind:mainfrom
HandSonic:fix/1693-mssql-pagination

Conversation

@HandSonic

Copy link
Copy Markdown
Contributor

Replaces closed #1895 with correct implementation.

When OFFSET...FETCH is unavailable (SQL Server < 2012), fall back to ROW_NUMBER() OVER() following the same pattern as DB2SqlBuilder. Previously buildPageLimit returned EMPTY causing pagination to silently return all rows.

Fixes #1693

…rMind#1693)

When OFFSET...FETCH is unavailable (SQL Server < 2012, version < 11),
fall back to ROW_NUMBER() OVER() window function, following the same
pattern used by the DB2 plugin.

The generated SQL wraps the original query:
  SELECT * FROM (SELECT TMP_PAGE.*, ROW_NUMBER() OVER(ORDER BY (SELECT NULL))
  AS CAHT2DB_AUTO_ROW_ID FROM (<original>) TMP_PAGE) TMP_PAGE
  WHERE CAHT2DB_AUTO_ROW_ID BETWEEN startRow AND endRow

Previously, buildPageLimit returned EMPTY for old versions, causing
pagination to silently return all rows.
@Chat2DB-Pro
Chat2DB-Pro merged commit 08b60af into OtterMind:main Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Persistent MSSQL Query Error - TOP/LIMIT

2 participants