If Object_ID('dbo.GetMasterGoods')IsNotNull Drop Proc dbo.GetMasterGoods Go
Create Proc GetMasterGoods @MyCursor Cursor Varying Output With Encryption As Set@MyCursor = Cursor For Select GoodsCode,GoodsName From Master_Goods Open @MyCursor Go 下边建立另外一个存储过程,用于遍历游标输出结果
Create Proc GetAllGoodsIDAndName As
Declare @GoodsCode varchar(18) Declare @GoodsName nvarchar(20) Declare @MasterGoodsCursor Cursor Exec GetMasterGoods @MasterGoodsCursor out Fetch Next From@MasterGoodsCursor InTo@GoodsCode,@GoodsName While(@@Fetch_Status = 0) Begin Begin Print@GoodsCode +':'+@GoodsName End Fetch Next From@MasterGoodsCursor InTo@GoodsCode,@GoodsName End Close @MasterGoodsCursor Deallocate @MasterGoodsCursor Go 最后执行Exec GetAllGoodsIDAndName结果为以下内容