sql 儲存過程 分頁

2022-02-03 19:31:34 字數 1641 閱讀 6316

--

-儲存過程:分頁,獲得第@endrecord-@num+1條到第@endrecord條記錄的研報資訊

ifexists (select

*from sysobjects where name=

'sp_reportpagelist

'and type='p

')drop

procedure

sp_reportpagelist

gocreate

procedure

sp_reportpagelist

@stockcode

nvarchar(20

),@num

int, --

條數@endrecord

int--

從0到該頁最後一條記錄的總記錄數

asbegin

select

top (@num) *

from

(select

top (@endrecord

) t1.reportid,t1.stockcode,t2.reporttitle,t3.sourceid,t3.companyname,t3.companyshortname,

case

when t1.grade=

0then

'不評級

'when t1.grade=

1then'**

'when t1.grade=

2then'增持

'when t1.grade=

3then'**

'when t1.grade=

4then'賣出

'when t1.grade=

5then'中性

'end

asgrade,

case

when t1.gradeupdate=

0then

'不評級

'when t1.gradeupdate=

1then'首次

'when t1.gradeupdate=

2then'調高

'when t1.gradeupdate=

3then'維持

'when t1.gradeupdate=

4then'調低

'end

asgradeupdate,

t1.targetprice,t2.reportdate

from

(select reportid,stockcode,grade,gradeupdate,targetprice from stockreview where stockcode=

'000002

'or stockname=

'000002

') t1

left

join report t2 on t1.reportid = t2.reportid left

join

company t3

on t2.companyid = t3.sourceid order

by t2.reportdate desc

) tt

order

bytt.reportdate

endgo

sql 儲存過程分頁

create proc myx prpagerecordset querystr nvarchar 1000 keyfield nvarchar 200 pagesize int,pagenumber int as begin declare sqltext as nvarchar 4000 dec...

SQL 儲存過程 分頁

1.俄羅斯儲存過程 的改良版 create procedure pagination1 pagesize int,頁面大小,如每頁儲存20條記錄 pageindex int 當前頁碼 as set nocount on begin declare indextable table id int id...

SQL 分頁儲存過程

create procedure splitpage sql nvarchar 4000 不帶排序語句的sql語句 page int,頁碼 recsperpage int,每頁容納的記錄數 id varchar 255 需要排序的不重複的id號 sort varchar 255 排序欄位及規則 as...