当前位置:   article > 正文

sql存储

sql存

1.查询前十条的四个SQL语句

  1. --第一种
  2. select top 10* from dbo.AdminInfo where AdminId not in(select top 10 AdminId from dbo.AdminInfo)
  3. --第二种
  4. select top 10* from dbo.AdminInfo where AdminId>(select MAX(AdminId) from dbo.AdminInfo where AdminId in(select top 10 AdminId from dbo.AdminInfo))
  5. --第三种
  6. select * from dbo.AdminInfo where AdminId between 11 and 20
  7. --第四种
  8. select * from (select *,ROW_NUMBER() over(Order by AdminId)as number from dbo.AdminInfo)t where t.number between 11 and 20;

2.页面存储

  1. create proc pagclistproc (@pageIndex int,@pagesize int,@tableName varchar(200),@ColumnName varchar(500),@Orderby varchar(50),@Sort varchar(50)
  2. )as
  3. Declare @sql nvarchar(2000);
  4. set @sql= 'select ' +@ColumnName +' from (select ' +@ColumnName + ' ,ROW_NUMBER() over(Order by ' +@Orderby+ ' )as number from ' +@tableName + ' )t where t.number between ' +CAST(((@pageIndex-1)*@pagesize)as varchar(200))+ ' and ' +CAST((@pageIndex*@pagesize)as varchar(200))
  5. exec(@sql)
  6. exec pagclistproc 1,10,'dbo.AdminInfo','*','AdminId','desc';

3.sql中创建循环的存储过程
 

  1. create procedure xuanhuan (@count int )
  2. as 
  3. declare @num int ;    
  4. set @num=@count;    
  5. while(@num>0)      
  6. begin                 
  7. print @num;          
  8. set @num-=1;      
  9. end                  
  10. exec dbo.xuanhuan 3    

 

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

闽ICP备14008679号