Hello guys,..... So i have a table that uses an SQL query meaning I cannot use the pagination widget on it..... I am struggling writing SQL code to make the pagination functional.. Please help
Hi @Ide Fatsha
Please check the below links:https://www.outsystems.com/forums/discussion/56822/reactive-web-application-paginate-a-table-with-an-advancedsql-source/#
https://www.outsystems.com/forums/discussion/56770/sql-offset-and-os-pagination/#
RegardsKrishnanand Pathak
Hello Ide Fatsha,
Here are some documentation links that might help you to understand how to perform pagination:
Best regards, Ana
Hi Ide Fatsha
you can implement pagination in your SQL query using the OFFSET and FETCH NEXT clauses.
Here is an example of how you can modify your SQL query to implement pagination:
sql
Copy code
SELECT *
FROM your_table
ORDER BY your_column
OFFSET (@pageNumber - 1) * @pageSize ROWS
FETCH NEXT @pageSize ROWS ONLY
In the above syntax, your_table is the name of the table you want to query, your_column is the column you want to use to order the results, @pageNumber is the number of the page you want to retrieve (starting from 1), and @pageSize is the number of rows you want to retrieve per page.
The OFFSET clause skips the first (@pageNumber - 1) * @pageSize rows, and the FETCH NEXT clause retrieves the next @pageSize rows. By combining these clauses with the ORDER BY clause, you can retrieve the rows in the desired order and retrieve only the rows for the requested page
Hi Ide Fatsha,
Please find the demo OML File.
Thanks,
Ramesh
Hi Ramesh,
If I test your SQL Query, I'm getting the following error message: "Database returned the following error: Error in advanced query SQL1: Incorrect syntax near '@qpinStartIndex'. Invalid usage of the option NEXT in the FETCH statement. "
However, If I publish it, your solution works.
I don't understand, how is that possible?
Laura
I had the same problem and managed to solve it by passing a default value to the TableSort variable.
Hello Ide,
The issue is not in the NEXT in the FETCH statement, the issue is in the ORDER BY clause.
You need to always have a default Sort By, or else the clause of ORDER BY your_column will give an error because the your_column is blank.