Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.nurkiewicz.jdbcrepository.sql;
 
SQLServer Pagination feature for SQLServer 2012+ -> extension of order by clause

See also:
http://msdn.microsoft.com/en-us/library/ms188385.aspx Author: tom
Sort by first column
	private static final String MSSQL_DEFAULT_SORT_CLAUSE = " ORDER BY 1 ASC";
	public String selectAll(TableDescription tablePageable page) {
		final int offset = page.getPageNumber() * page.getPageSize() + 1;
		String sortingClause = super.sortingClauseIfRequired(page.getSort());
		if (!StringUtils.hasText(sortingClause)) {
			//The Pagination feature requires a sort clause, if none is given we sort by the first column
			sortingClause = ;
		}
		final String paginationClause = " OFFSET " + (offset - 1) + " ROWS FETCH NEXT " + page.getPageSize() + " ROW ONLY";
		return super.selectAll(table) + sortingClause + paginationClause;
	}
New to GrepCode? Check out our FAQ X