Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to operate MSSQL query data paging

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article is to share with you about how to operate MSSQL query data paging. The editor thought it was very practical, so I shared it with you as a reference. Let's follow the editor and have a look.

Method 1: use select top with not in (or not exists) to filter out the data on page 1 when querying page n. The example assumes that the number of queries per page is 5, and the data on page 3 is queried.

Select Top 5 UserCode,UserName from userInfo where UserCode not in (select top ((3-1) * 5) UserCode from UserInfo order by UserCode asc) order by UserCode asc

The first 15 rows of data

The data on page three

Note that order by must use the same columns and arrangement when querying

Method 2: using the Row_Number () built-in function, first add a column of ID to the query table, and then query the pages of the between.. and... is very simple.

Select UserCode,UserName,PassWord From

(Select UserCode,UserName,PassWord,Rn=Row_Number () OVER (order by UserCode desc) From UserInfo) AS T

Where t.Rn between (3-1) * 5 and 3

Of course, in the actual application, the number of records per page can be replaced by parameters on which page of the query.

Thank you for reading! On how to operate MSSQL query data paging to share here, I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, you can share it and let more people see it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report