Implementation of service-side paging in project combat--sql

Source: Internet
Author: User

The service side of the page on a SQL statement can be done, paste the code after you slowly appreciate:

CREATE Procedure Appgetemplist

@EID int,

@LGID int,

@pagesize int,

@pageindex int

As

Begin

Select COUNT (*) Count from Appemployee

Select a.id,a.eid,case when @LGID =2052 then Name Else ename End name,deptitle,jobtitle

, case when B.xeid was null then 0 Else 1 End Fav

, Case if Isnull (a.reportto,0) [email protected] then 1 Else 0 End issub

From (select Row_number () over (order by left (a.ename,1)) ID, a.*

From Appemployee A

Where [email protected] and Isnull (a.status,0) <>4) a

Left Join Appempfavorites B on A.eid=b.eid and [email protected]

where a.id between (@pageindex-1) * @pagesize +1 and @pageindex * @pagesize

End


Analysis 1:

Select Row_number () over (order by left (a.ename,1)) ID, a.*

From Appemployee A

Where [email protected] and Isnull (a.status,0) <>4)

This section of the statement is the main Table Appemployee assignment of an ID, convenient for paging processing, but also by the name of the English name to sort!


Analysis 2:

Select a.id,a.eid,case when @LGID =2052 then Name Else ename End name,deptitle,jobtitle

, case when B.xeid was null then 0 Else 1 End Fav

, Case if Isnull (a.reportto,0) [email protected] then 1 Else 0 End issub

From (select Row_number () over (order by left (a.ename,1)) ID, a.*

From Appemployee A

Where [email protected] and Isnull (a.status,0) <>4) a

Left Join Appempfavorites B on A.eid=b.eid and [email protected]

This statement is based on statement 1 through the Eid filter out the values we do not need


Analysis 3:

where a.id between (@pageindex-1) * @pagesize +1 and @pageindex * @pagesize

The statement is evaluated by passing parameters and the specified value is fetched back to the client.


In summary, the service side only need to use this idea can realize the paging query function, however, the Android client in the ListView using Paging Request method (client paging follow-up discussion), can be connected to the server.


This article is from the "Suck on self-renewal" blog, please be sure to keep this source http://wyong.blog.51cto.com/1115465/1618762

Implementation of service-side paging in project combat--sql

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.