create proc test2
as
begin
declare @i int
declare @m int
declare @n int
declare @table1 table(id int identity,num int)
set @i=1
set @n=1
set @m=0
while @i<=100
begin
declare @j int
INSERT INTO @table1(num)
SELECT CAST(RAND()*100 AS INT)+1
set @i=@i+1
end
while @n<=100
begin
select @m=@m+num from @table1 where id=@n
set @n=@n+1
end
print @m
end
--运行:
test2