万能存储过程

Posted xuyuequan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了万能存储过程相关的知识,希望对你有一定的参考价值。

--分页
  create proc e_page
  (
  @pageIndex int,--当前页索引
  @pageSize int, --一页显示几条
  @allcount int output,  --一共有多少条数据
  @name  nvarchar(20)=null --模糊查询
  )
  as
  declare  @startRow int ,@endRow int   --定义两个变量 
  set @startRow=(@pageIndex-1)*@pageSize+1
  set @[email protected][email protected]
  if(@name is null)
  begin
  select @allcount=(select count(*) from Student)
  select * from (select ROW_NUMBER() over(order by (Student.ID))as bid,*from Student)  as temp where temp.bid between @startRow and @endRow
  end
  else
  begin
  set @allcount=(select count(*) from Student  where Student.Name like ‘%‘[email protected]+‘%‘)
   select * from (select ROW_NUMBER() over(order by (Student.ID))as bid,*from Student where  Student.Name like ‘%‘[email protected]+‘%‘) as temp where temp.bid between @startRow and @endRow
  end

  select * from Student  where Student.Name like ‘%大%‘
  create database Stu
  use Stu
  create table Student
  (
  ID int identity,
  Name varchar(20),
  Age varchar(20),
  Crade varchar(20)
  )
  create proc e_GetList
  as
  begin
  select * from Student
  end
  --查询
  create proc e_GetLists
  @name varchar(50),
  @age varchar(50)
  as
  begin
  declare @sql varchar(500)
  set @sql = ‘select * from  Student where 1=1‘
  if(@name!=‘‘)
  set @sql+=‘and Name like‘+‘‘‘‘+‘%‘[email protected]+‘%‘+‘‘‘‘;
  if(@age!=‘‘)
  set @sql+=‘and Age=‘‘‘[email protected]+‘‘‘‘;
  exec(@sql)
  end
  exec e_GetLists ‘a‘,null
  --添加
  create proc e_Add
  (@Name varchar(20),
  @Age varchar(20),
  @Crade varchar(20)
  )
  as
  begin
  insert into Student values(@Name,@Age,@Crade)
  end
  drop proc e_Add
  --删除
  create proc e_delete
  (
 @nid varchar(50)
  )
  as
  begin
  exec(‘delete from Student where ID in (‘[email protected]+‘)‘)
  end
  --返填
  create proc e_GetListById
  (
 @id int
  )
  as
  begin
  select * from Student where [email protected]
  end
  --修改
  create proc e_update
  (
 @Name varchar(20),
 @Age varchar(20),
 @Crade  varchar(20),
 @ID int
  )
  as
  begin
  update Student set [email protected],[email protected],[email protected] where [email protected]
  end
























































































以上是关于万能存储过程的主要内容,如果未能解决你的问题,请参考以下文章

存储过程万能分页

万能分页存储过程

万能分页存储过程

SQL 高效的万能分页语句

java高级特性:使用反射实现万能序列化1

存储过程调用存储过程的语法