sql存储

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

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

2.页面存储

create proc pagclistproc (@pageIndex int,@pagesize int,@tableName varchar(200),@ColumnName varchar(500),@Orderby varchar(50),@Sort varchar(50)
)as
Declare @sql nvarchar(2000);
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))
exec(@sql)
exec pagclistproc 1,10,'dbo.AdminInfo','*','AdminId','desc';

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

create procedure xuanhuan (@count int )
as 
declare @num int ;    
set @num=@count;    
while(@num>0)       
begin                 
print @num;          
set @num-=1;       
end                   
exec dbo.xuanhuan 3    

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值