SqlServer paging ROW

Source: Internet
Author: User
Syntax: select * from (select *, ROW_NUMBER () OVER (Orderbya. CreateTimeDESC) ASRowNumberfromtable_nameasa) select * from (selectROW_NUMBER () over (orderbyDWHYBH) asrowNo, * from

Syntax: select * from (select *, ROW_NUMBER () OVER (Order by. createTime DESC) AS RowNumber from table_name as a) as B where RowNumber BETWEEN 1 and 5 instances select * from (select ROW_NUMBER () over (order by DWHYBH) as rowNo, * from


Syntax:

Select * from (

Select *, ROW_NUMBER () OVER (Order by a. CreateTime DESC) AS RowNumber from table_name as
) As B

Where RowNumber BETWEEN 1 and 5

The instance is as follows:

Select * from
(
Select ROW_NUMBER () over (order by DWHYBH) as rowNo, * from C60DWYHXX
) As t
Where rowNo between 4 and 8
And t. DWJC like '%'
And t. DWQC like '%'



The data table used is:

Create table [dbo]. [C60DWYHXX] (
[DWHYBH] [varchar] (20) not null primary key,
[DWJC] [varchar] (20) not null,
[DWQC] [varchar] (60) not null,
[DWLB] [int] not null,
[FRDB] [dbo]. [xm] NULL,
[FRDBZSH] [varchar] (30) NULL,
[LXR] [dbo]. [xm] NULL,
[LXRMOBILE] [dbo]. [mobile] NULL,
[QYEMAIL] [varchar] (50) NULL,
[DWLANDLINE] [varchar] (15) NULL,
[QYWZDZ] [varchar] (40) NULL,
[YHMM] [char] (32) NULL,
[DJRQ] [date] NULL,
[UniqueID] [int] not null,
[WTag] [int] NULL,
[StrTag] [varchar] (255) NULL,
[RecVersion] [bigint] NULL,
[YHID] [uniqueidentifier] NULL
)



Part 2: Self-written SQL statements that are spliced at the provincial, municipal, and county levels



SELECT ROW_NUMBER () OVER (order by HYBH) AS rowNo, B. XM




,(
Select xzqhwm from Z21XZQH e where e. XZQH in (select SUBSTRING (f. xzqh, 0000) + '123' from C02YHJBXX f
Left join Z21XZQH d on f. XZQH = d. XZQH
Where f. XZQH = d. XZQH and f. YHID = a. YHID) as fir
,(
Select xzqhwm from Z21XZQH e where e. XZQH in (select SUBSTRING (f. xzqh, 0, 5) + '00' from C02YHJBXX f
Left join Z21XZQH d on f. XZQH = d. XZQH
Where f. XZQH = d. XZQH and f. YHID = a. YHID) as sec
,(
Select XZQHWM
From C02YHJBXX c
Left join Z21XZQH d on c. XZQH = d. XZQH
Where c. XZQH = d. XZQH and c. YHID = a. YHID
) As thir


, B. XZQH, a. HYBH, a. YHID, a. UniqueID
From C70HYGR a left join C02YHJBXX B on a. YHID = B. YHID
Where 1 = 1




-- Select SUBSTRING (XZQH, 0000) + '000000' from C02YHJBXX
-- Select xzqh from C02YHJBXX


Shows the query result.



The in keyword is nested in the subquery. Hey. Efficiency should not be high. However, the provincial write code is spliced into a datatable.

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.