概述ALTER PROCEDURE usp_XXXXXX (@DateFrom VARCHAR(20), @DateTo VARCHAR(20)) AS DECLARE @PLTID VARCHAR(20) --Pallet ID DECLARE @CTNID VARCHAR(30) --Carton ID DECLARE @intError INT DECLARE ALTER PROCEDURE usp_XXXXXX (@DateFrom VARCHAR(20),@Dateto VARCHAR(20)) AS DECLARE @pltID VARCHAR(20) --Pallet ID DECLARE @CTNID VARCHAR(30) --Carton ID DECLARE @intError INT DECLARE @strsql NVARCHAR(3000) DECLARE @Cnt INT SET @CTNPERplt=100 SET @Cnt=0 DECLARE plt_cursor CURSOR SCRolL FOR SELECT disTINCT PalletNo FROM **** WITH(NolOCK) order by palletno OPEN plt_cursor FETCH NEXT FROM plt_cursor INTO @pltID WHILE @@FETCH_STATUS=0 BEGIN SELECT top 1 @SNQTYONplt=Qty,@PN=PN,@SO=SO,@shipment=shipment,@mfdate=mfdate,@timein=timein FROM **** WITH(NolOCK) WHERE **** IF LEN(@SNQTYONplt)=0 OR LEN(@PN)=0 OR LEN(@SO)=0 OR LEN(@shipment)=0 OR LEN(@mfdate)=0 OR LEN(@timein)=0 BEGIN RAISERROR ('Some Column is NulL.',16,1) SET @intError=0 GOTO Err_Handle END BEGIN TRAN SET @strsql='INSERT INTO ****' SET @strsql=@strsql +'****' EXEC @intError=SP_EXECUTEsql @strsql IF @intError <> 0 BEGIN GoTo Err_Handle END SET @CTNSEQ=1 IF UPPER(left(Rtrim(Ltrim(@PN)),2))='9B' BEGIN DECLARE CTN_cursor CURSOR SCRolL FOR SELECT **** FROM **** WHERE trID IN (****) OPEN CTN_cursor FETCH NEXT FROM CTN_cursor INTO @CurCTNID WHILE @@FETCH_STATUS=0 BEGIN BEGIN TRAN SELECT @SNQTYONCTN=count(*) FROM **** WHERE carton=@CurCTNID SET @strsql='INSERT INTO ****' SET @strsql=@strsql +'****' EXEC @intError=SP_EXECUTEsql @strsql IF @intError <> 0 BEGIN GoTo Err_Handle END SET @CTNSEQ=@CTNSEQ+1 END CLOSE SN_cursor DEALLOCATE SN_cursor IF @@trancount<>0 BEGIN COMMIT TRAN END FETCH NEXT FROM CTN_cursor INTO @CurCTNID END CLOSE CTN_cursor DEALLOCATE CTN_cursor GOTO Newplt END Newplt: UPDATE **** SET **** WHERE **** IF @@ERROR<>0 GOTO Err_Handle ELSE IF @@trancount<>0 BEGIN COMMIT TRAN END FETCH NEXT FROM plt_cursor INTO @pltID SET @Cnt=@Cnt+1 END IF @@ERROR<>0 GOTO Err_Handle ELSE IF @@trancount<>0 BEGIN COMMIT TRAN END CLOSE plt_cursor DEALLOCATE plt_cursor RETURN 0 Err_Handle: IF @@trancount<>0 BEGIN RolLBACK TRAN END RETURN @@ERROR 总结
以上是内存溢出为你收集整理的SqlServer 较可以学习的存储过程 对事务,出现错误的导向全部内容,希望文章能够帮你解决SqlServer 较可以学习的存储过程 对事务,出现错误的导向所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
评论列表(0条)