读书人

写一个存储过程执行时候execute(1)

发布时间: 2012-10-13 11:38:17 作者: rapoo

写一个存储过程,执行时候execute(1),写入一万个数据,编译有错误
create procedure p
@strSql int
as
begin
while @strSql<10000
begin
insert into t_practice
values (@strSql,100)
end
@strSql=@strSql+1
end


[解决办法]
下面这样,变量赋值要用set 或者select
并且要把赋值的也放到while 循环体里面

SQL code
create procedure p  @strSql int  asbeginwhile @strSql<10000begininsert into t_practice values (@strSql,100)SET @strSql=@strSql+1endend 

读书人网 >SQL Server

热点推荐