存储过程中将sql语句结果赋值给变量create procedure procname
AS
declare@recount int
lect@recount=count(id) from school补刀
--最关键在这句
lect@recount=count(id) from school
lect@recount=lect count(id) from school -- 错误:这⾥就不再需要lect了
残疾儿童
t@recount=count(id) from school -- 错误这⾥只能⽤lect不能⽤t
放烟花
如果school为⼀个@chart参数的话,上⾯⽅法就不适⽤了
应该为:
围棋零基础入门
declare@getRecordSql nvarchar(100)
读围城有感
t@getRecordSql='lect @recordcount=count(1) from '+@chart
exec sp_executesql @getRecordSql,N'@recordCount int output',@recordCount output
int output',@recordCount output
做⼀个参数的替换,如果测试⼀下:print @recordCount的话就会显⽰⾏数
//⽰例:选择最新的5条数据从20条开始意念减肥法
execute A_School_getNew 5,20
--存储过程肠胃不舒服吃什么比较好
create procedure A_School_getNew
@Size int,
@StartIndex int
AS
declare@recount int
declare@Sql nvarchar(120)
lect@recount=count(id) from school
t@Sql='lect top '+convert(nvarchar,@Size)+'id,school_name from school where('+out短语
'ID not in(lect top '+convert(nvarchar,@recount-@startIndex+@size)+
' id from school)) order by id desc';
execute (@Sql)