DECLARE @BillId BIGINT DECLARE @CompId BIGINT DECLARE @BizType VARCHAR(10) DECLARE @Dues DECIMAL(18,6) DECLARE @BillMemo VARCHAR(MAX) DECLARE @BillType VARCHAR(MAX) DECLARE @BillTime DATETIME DECLARE @BillNo VARCHAR(max) DECLARE @MemId BIGINT DECLARE @MemNo VARCHAR(max) DECLARE Cur CURSOR FOR SELECT FBillId ,FCompId,FBizType,FDues,FBillTime,FBillMemo,FMemId,FMemNo,FBillNo FROM TMemberSaleBill WHERE FState = 1 OPEN Cur FETCH Cur INTO @BillId,@CompId,@BizType,@Dues,@BillTime,@BillMemo,@MemId,@BillMemo,@BillNo WHILE @@FETCH_STATUS=0 BEGIN PRINT @BillId DECLARE @Sql VARCHAR(MAX) EXEC PAuditMemberSaleDetailSplit @BillId,@CompId, @BizType ,@Dues EXEC PAuditMemberSaleTransHist @BillId ,@CompId,@BillNo,@BillTime ,'KK' ,@BizType,@MemId ,@MemNo,@BillMemo EXEC (@sql) FETCH Cur INTO @BillId,@CompId,@BizType,@Dues,@BillTime,@BillMemo,@MemId,@BillMemo,@BillNo END CLOSE CUR DEALLOCATE CUR