...
CREATE proc [dbo].[Sys_Rebate_Equity] AS declare @fMemberID varchar(50)--用戶ID declare @Rebate decimal(18,2)--總股權數 BEGIN begin try Begin Transaction --開始事務 DECLARE cursor1 CURSOR for --定義游標cursor1 select fMemberID,sum(fNumber) as 'fNumber' from BP_Equity where fNumber>0 group by fMemberID --使用游標的對象 open cursor1 --打開游標 fetch next from cursor1 into @fMemberID,@Rebate --將游標向下移1行,獲取的數據放入之前定義的變數@fMemberID,@Rebate中 while @@FETCH_STATUS=0 --判斷是否成功獲取數據 begin select 1 --進行相應處理 fetch next from cursor1 into @id --將游標向下移1行 end close cursor1 --關閉游標 deallocate cursor1 --刪除游標引用 select 888 Commit Transaction --提交事務 End Try Begin Catch if @@trancount > 0 ROLLBACK TRANSACTION --回滾事務 Select 8888 End Catch END