当前位置:   article > 正文

四种查询SQL语句方法及两种存储过程_sql查询有哪些存储过程

sql查询有哪些存储过程

 

  1. //四种查询的方法:
  2. 第一种(top):select top 10 * from dbo.Admin where Id not in(select top 10 Id  from dbo.Admin)
  3. 第二种(max):select top 10 * from dbo.Admin where Id >
  4.               (select Max(Id) from dbo.Admin where Id in(select top 10 Id from dbo.Admin))
  5. 第三种(between-and):select * from dbo.Admin where Id between 11 and 20;
  6. 第四种(row-number):select * from (select *, Row_Number()over(order by Id)as number from dbo.Admin)t
  7.                   where t.number between 11 and 20;

 

  1. //循环存储过程:
  2. CREATE PROCEDURE XH(@Z int)
  3. as 
  4. declare @a int;
  5. set @a = @Z;
  6. while(@a>0)
  7. begin
  8. print @a;
  9.  set @a = @a - 1;
  10. END
  11. //分页存储过程:
  12. create procedure sqlvj
  13. (
  14.     @YS int,
  15.     @XSTS int,
  16.     @BM varchar(200),
  17.     @ZJ varchar(100),
  18.     @LM varchar(50),
  19.     @PX varchar(100)
  20. as
  21. DECLARE @sql varchar(200);
  22. DECLARE @A1 varchar(50);
  23. DECLARE @A2 Varchar(50);
  24. SET @A1 = CAST((@YS-1)*@XSTS as varchar(50));
  25. SET @A2 = CAST(@YS*@XSTS as varchar(50));
  26. SET @sql = CAST('select ' +@LM+ ' from ' +@BM+ ' where ' + @ZJ+ ' BETWEEN ' +@A1+ ' AND ' +@A2+ ' ORDER BY ' +@ZJ+ ' ' +@PX+ ' ' as varchar(200));
  27. exec(@sql)
  28. //调循环和分页的方法:
  29. exec XH 5;
  30. exec sqlvj 1,10,'Admin','Id','*','ASC';


 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/168722?site
推荐阅读
相关标签
  

闽ICP备14008679号