Copy codeThe Code is as follows:
Create procedure p_News
@ PageSize int, @ pageIndex int
As
Begin
Select * from (
Select *, Row_Number () over (order by Id) as [$ Row_Num] from News
-- Where [$ Row_Num] <= 3. The row number cannot be used at this time. It is generated only after all the execution is complete.
) As _ temp where [$ Row_Num] between (@ pageIndex * pageSize + 1) and (@ pageIndex + 1) * @ pageSize
End
-- Note parameter settings. String SQL = "{call p_News (?,?)} "
-- Select Row_Number () over (order by id) RN, * from News where id> 3. encode a number for the final result, a continuous number.
-- Order by must be written in parentheses, because an SQL error will be reported after being written in from News: Unless TOP or FOR XML is also specified, the order by clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions.