从 Northwind 库表Orders 取出 OrderID 累加输出
CREATE proc test
@StartOrderID int,
@EndOrderID int,
@Code varchar(1000) Out
As
Begin
Declare @tmp int
Set @Code=''
Declare #cur_orders cursor for Select OrderID From Orders
where OrderID>=@startOrderID and OrderID<=@EndOrderID
for read only
Open #cur_Orders
fetch next from #cur_orders into @tmp
while @@fetch_Status=0
Begin
Set @Code=@Code+'-'+convert(varchar(8),@tmp)
print @code
fetch next from #cur_orders into @tmp
End
close #cur_Orders
Deallocate #cur_Orders
return
End
GO
执行存储过程:
declare @a varchar(1000)
-exec test 10248, 10253 ,@a
结果如下: