SQL 儲存過程的分頁

2021-04-25 16:06:07 字數 2554 閱讀 1043

create procedure

--ty_exchange_search_my_projects @usercode=1500

--select * from t_user

[dbo].[ty_exchange_search_my_projects_shark]

(@pmiuserfid int ,

@datebegin datetime = '2005-01-01',

@dateend datetime = '3000-01-01',

@page_index int = 0 ,

@page_size int = 15)as

begin

set @datebegin = cast(convert(varchar(100),@datebegin,23) + ' 00:00:00' as datetime)

set @dateend = cast(convert(varchar(100),@dateend,23) + ' 23:59:59' as datetime)

set nocount on;

set   ansi_nulls   off

declare @s int set @s = @page_index * @page_size + 1

declare @e int set @e = @s + @page_size

select * from

(select c_code, c_title,c_event_desc, row_number() over ( order by c_fid asc) as rn

from

(select a.c_code, a.c_title,a.c_event_desc,a.c_fid

from dbo.syn_tu_event a inner join syn_ty_wf_ex_local_act_inst b  on a.c_wf_inst_id=b.workflow_instance_id

where b.in_date between @datebegin and  @dateend and  b.receive_type_id = 100602 and b.receive_object_id in

(select r.role_id from  syn_ty_pmi_user as u inner join  syn_t_userrole as r on u.user_id = r.user_id where (u.fid = @pmiuserfid)

) union all

select a.c_code, a.c_title,a.c_event_desc,a.c_fid

from dbo.syn_tu_event_finish a inner join syn_ty_wf_ex_local_act_inst b  on a.c_wf_inst_id=b.workflow_instance_id

where b.in_date between @datebegin and  @dateend and  b.receive_type_id = 100602 and b.receive_object_id in

(select r.role_id from  syn_ty_pmi_user as u inner join  syn_t_userrole as r on u.user_id = r.user_id where (u.fid = @pmiuserfid)

) ) b

) fk where rn >= @s and rn < @e

select count(1) as icount from

(select a.c_code, a.c_title,a.c_event_desc

from dbo.syn_tu_event a inner join syn_ty_wf_ex_local_act_inst b  on a.c_wf_inst_id=b.workflow_instance_id

where b.receive_type_id = 100602 and b.receive_object_id in

(select r.role_id from  syn_ty_pmi_user as u inner join  syn_t_userrole as r on u.user_id = r.user_id where (u.fid = @pmiuserfid)

) union all

select a.c_code, a.c_title,a.c_event_desc

from dbo.syn_tu_event a inner join syn_ty_wf_ex_local_act_inst b  on a.c_wf_inst_id=b.workflow_instance_id

where b.receive_type_id = 100602 and b.receive_object_id in

(select r.role_id from  syn_ty_pmi_user as u inner join  syn_t_userrole as r on u.user_id = r.user_id where (u.fid = @pmiuserfid)

)) a

end

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...