日期:2014-05-17 浏览次数:20488 次
--分页查询的入库明细存储过程 sp_select_rkdetails
if exists(select * from sysobjects where name='sp_select_rkdetails')
drop proc sp_select_rkdetails
go
create proc sp_select_rkdetails
(
@pageIndex int, --当前页码
@pageSize int, --每页显示的数目
@orderId varchar(50)=null, --入库单ID
@bianma varchar(50)=null, --产品编码
@cpXH varchar(50)=null --产品型号
)
as
DECLARE @sq_sql varchar(1000)
set @sq_sql = N'select top @pageSize * from tb_rkdetails where k_id not in(select top @pageSize*(@pageIndex-1) from tb_rkdetails)'
if @orderId is not null
begin
set @sq_sql = @sq_sql+ N' and k_by1 like N''%'+@orderId+'%'''
end
if @bianma is not null
begin
set @sq_sql = @sq_sql+ N' and k_cpBianma like N''%'+@bianma+'%'''
end
if @cpXH is not null
begin
set @sq_sql = @sq_sql+ N' and k_cpXHnumber like N''%'+@cpXH+'%'''
end
Execute @sq_sql
go
//调用存储过程
Exec sp_select_rkdetails '2','15','','',''
set @sq_sql = N'select top '+@pageSize'+ * from tb_rkdetails where k_id not in(select top '+@pageSize*(@pageIndex-1)+' from tb_rkdetails)'