저장 프로시저 - 제거

1451 단어 저장 프로세스
USE [mo]

GO



/****** Object:  StoredProcedure [dbo].[PR_DelProduceDeclare]    Script Date: 11/28/2011 10:38:05 ******/

SET ANSI_NULLS ON

GO



SET QUOTED_IDENTIFIER ON

GO



create PROCEDURE [dbo].[PR_DelProduceArrange1]

(

@Id int,

@LastUpdateTime datetime

)

AS

BEGIN

    SET NOCOUNT ON

    DECLARE @TranStarted bit

    SET @TranStarted = 0

    IF( @@TRANCOUNT = 0 )

    BEGIN

        BEGIN TRANSACTION

	 SET @TranStarted = 1

    END

    ELSE

    	SET @TranStarted = 0



	if not exists(select Id from PR_ProduceDeclare where Convert(varchar(20),LastUpdateTime,120)=Convert(varchar(20),@LastUpdateTime,120) and id=@Id)

	begin

		IF( @TranStarted = 1 )

		BEGIN

			SET @TranStarted = 0

			ROLLBACK TRANSACTION

		END

		return -3

		end

	if  exists(select Id from PR_ProduceDeclare where ProduceState<>0 and id=@Id)

	begin

		IF( @TranStarted = 1 )

		BEGIN

			SET @TranStarted = 0

			ROLLBACK TRANSACTION

		END

		return -2

		end	

		

   delete PR_DeclareCommodity where D_Id=@Id

   delete PR_ProduceDeclare where Id=@Id

   

    



    IF( @@ERROR <> 0 )

    BEGIN

        GOTO Cleanup

    END



    IF( @TranStarted = 1 )

    BEGIN

	 SET @TranStarted = 0

	 COMMIT TRANSACTION

    END



    RETURN 1

Cleanup:

    IF( @TranStarted = 1 )

    BEGIN

        SET @TranStarted = 0

        ROLLBACK TRANSACTION

    END

    RETURN 0

END



GO


  
편집기 로드 중...

좋은 웹페이지 즐겨찾기