--切换到db_StuManagement数据库
use db_StuManagement
go
--分页查询
--判断存储过程是否存在
if exists(SELECT * FROM sys.objects where name='proc_PagePaging')
drop proc proc_PagePaging
go
--创建存储过程
create proc proc_PagePaging
--声明参数
@stuNumber varchar(16),
@stuSex int,
@pageIndex int,
@pageSize int,
@tbName varchar(18),
@rowCount int output
as
BEGIN
--声明变量
DECLARE @sqlStr nVARCHAR(500)
SET @sqlStr='select * from '+@tbName+' where 1=1 '
DECLARE @whereStr nVARCHAR(500)
SET @whereStr=''
print @sqlStr
--添加学生学号查询条件
IF(@stuNumber!='' AND @stuNumber IS NOT NULL)
BEGIN
SET @whereStr=' and stuNumber LIKE ''%'+@stuNumber+'%'''
END
--添加学生性别查询条件
IF(@stuSex IS NOT NULL)
BEGIN
SET @whereStr+=' and stuSex='+cast(@stuSex as varchar)
END
--条件拼接完成
SET @sqlStr+=@whereStr
print @sqlStr
select @rowCount=count(0) from stuMessage
declare @sumIndex int
set @sumIndex=CEILING(CAST(@rowCount as float)/cast(@pageSize as float))
print