create PROCEDURE PrcTestByPage ( @tablename varchar(50), @selectfilter varchar(100), @orderbyfilter varchar(100), @selectpage int, @pageSize int ) AS BEGIN -- 存储过程开始 declare @pkname varchar(100) -- 获取表的主键名称 SELECT @pkname=COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE [email protected] declare @num int set @num=(@selectpage-1)*@pageSize declare @strsqltwo varchar(4000) set @strsqltwo=‘select top ‘+STR(@num)+‘ ‘[email protected]+‘ from ‘[email protected] DECLARE @strSql varchar(4000) --SQL执行语句 set @strSql=‘select top ‘+str(@pageSize)+‘ * from ‘[email protected] if(len(@selectfilter)>0) -- 判断有没有where条件 BEGIN set @[email protected]+‘ where ‘[email protected] SET @strSql = @strSql+‘ where ‘[email protected]+‘ and ‘[email protected]+‘ not in(‘[email protected]+‘)‘ END else SET @strSql = @strSql+‘ where ‘[email protected]+‘ not in(‘[email protected]+‘)‘ if(len(@orderbyfilter)>0) --判断有没有排序条件 BEGIN set @[email protected]+‘ order by ‘[email protected] SET @strSql = @strSql+‘ order by ‘[email protected] END EXEC (@strSql) END -- 存储过程结束 GO exec PrcTestByPage ‘Print_order‘,‘‘,‘‘,2,6
时间: 2024-10-12 15:57:05