|
- 5 l& t# ?# z) e
- --创建存储过程
[3 ^" g1 ]& y( O. W/ f - if exists(select * from sysobjects where name='P_GetStudentInfoPage')
9 O7 [% n1 G; a3 }- A( J8 c* L% ] - drop proc P_GetStudentInfoPage6 z; p9 I% G$ d
- go6 f# d$ [/ m" z6 n! L
- create proc [dbo].P_GetStudentInfoPage' k6 u7 K- [7 p" m, a6 M, c! v8 u8 P
- (
# L f+ `$ t) ? - @pageIndex int=1,--页号
; a: N& F2 R( s ?6 M - @pageSize int=10--每页数据条数
$ x) @/ ]( }9 J) j - )
4 O* m% I2 Z8 Q5 [! I/ K - as: y' b" P6 k, A" c& ]/ L
- --select count(*) from StudentInfo --查询数据总数3 [1 w% V9 B0 f! i* k4 C
- & w+ G1 X- W: u0 f
- select * from
& n O x% p9 ^# w; ~& p - (select ROW_NUMBER() over(order by StudentNo) as rowNum,* from StudentInfo) as tbl
1 w' _8 N8 _2 g5 O - where tbl.rowNum between ((@pageIndex - 1)* @pageSize + 1) and (@pageIndex*@pageSize)
& i) R- ]& \# N4 M( p; Z) i
( t; w6 G6 r: V* w5 `7 H- GO
: f, _ i+ i$ H! W! M K! m - * D, h. j8 \. o! M$ u5 _; G
- --调用
7 F& Y4 y6 |' j# M. X" w - % B: e1 O, V2 v5 m1 T
- EXEC P_GetStudentInfoPage 1,106 B8 `! Y d* I- q7 a7 K
2 f2 Y* q! l9 m4 s- EXEC P_GetStudentInfoPage 2,10% K- V2 m0 E) _9 F I' Z+ p3 P
- : Q8 f" L5 t7 F2 e% \" g! o
- --------------------------------------直接查询代码
Y2 E6 s5 y' u* T l; t/ x - select * from StudentInfo where id>=1 and id<=10
! g5 ?% h9 j* c5 d- W! f% W: b - select * from StudentInfo where id>=10 and id<=20 N9 v0 q8 C6 N1 g I
! Z1 B; k# R" S% f1 L" d- select * from StudentInfo where id between (1-1)*10+1 and 10 *12 B3 s( L$ s `
- select * from StudentInfo where id between (2-1)*10+1 and 10 *2
r! ]* ~' B9 s7 P
" t8 N; e* e0 K2 w$ e1 [+ o" ~- select (1-1)*10+1 --1% I3 t$ K/ E- `% y, @
- select (2-1)*10+1 --11
# c" P/ ]! f* I6 V - select (3-1)*10+1 --21' E- \( s8 [8 Y# k$ J
+ P8 X: s2 p/ A- select * from StudentInfo where id between 11 and 20
0 y9 e, {$ J6 I, z+ R! U
7 O7 f5 |5 _& I: S- select * from
+ }6 s. D5 D7 c4 ?9 y' N - (select ROW_NUMBER() over(order by StudentNo desc) newRows,* from StudentInfo) t) H' P' Q: T5 ?% |& q' j( D: k
- where t.newRows between (1-1)*10+1 and 10 *1
复制代码 |
|