Skip to content
Advertisement

How to add pagination to this dynamic sql

I have the following table with its respective data

I wanted to be able to sort the dynamic column example sort by ‘StudentName’ ASC it would sort data using column returning

When sorting by StudentName:

When sorting by Grade ASC:

When sorting by TeacherName ASC (different table)

I have manage to accomplish this.

The problem is adding Pagination to my dynamic SQL string.

This is my stored procedure

I just added the

and now it doesn’t work

Advertisement

Answer

The OFFSET and FETCH clauses are the options of the ORDER BY clause. They allow you to limit the number of rows to be returned by a query. https://www.sqlservertutorial.net/sql-server-basics/sql-server-offset-fetch/ I think you need to declare ORDER BY

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement