Вопрос

How can I paginate the results of a query using QueryDSL in older versions of MS SQL Server? For Oracle and SQL Server 2012+ I can do this:

query.offset(startIndex).limit(size);

However, this doesn't work in older versions of SQL server since offset isn't supported. I know the SQL code that needs to be gerenated is something like this:

SELECT  *
FROM    ( SELECT    ROW_NUMBER() OVER ( ORDER BY OrderDate ) AS RowNum, *
          FROM      Orders
          WHERE     OrderDate >= '1980-01-01'
        ) AS RowConstrainedResult
WHERE   RowNum >= 1
    AND RowNum < 20
ORDER BY RowNum

What's the best way to do this in QueryDSL?

Это было полезно?

Решение

Querydsl provides three different SQLServer dialects

  • SQLServerTemplates for SQL Server versions before 2005
  • SQLServerTemplates2005 for SQL Server 2005 and 2008
  • SQLServerTemplates2012 for SQL Server 2012

SQLServerTemplates doesn't support offset, but the other two do

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top