SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- by Pribadi Pamungkas. 2017-10-31.
-- stored procedure untuk mengupdate eform


CREATE PROCEDURE dbo.proc_update_eform
	@pi_eform_id INT, 
	@pi_eform_code VARCHAR(8), 
	@pi_transaction_type_id INT, 
	@pi_is_need_surat_kuasa VARCHAR(1), 
	@pi_remarks VARCHAR(255), 
	@pi_status_id INT, 
	@pi_is_delete VARCHAR(1),
	@po_message VARCHAR(400)
AS
BEGIN

	SET NOCOUNT ON;	-- SET NOCOUNT ON added to prevent extra result sets from interfering with SELECT statements.

	DECLARE 
	  @v_result BIT = 0,
	  @v_current_datetime DATETIME = GETDATE()

	BEGIN TRY
	BEGIN TRANSACTION

		IF (@@ROWCOUNT = 0) OR (@@ERROR <> 0)
			BEGIN
				SET @po_message = 'Failed update t_transaction'
				GOTO ERROR_OUT
			END

		COMMIT TRANSACTION
		SET @po_message = 'Sukses'  -- variable output 
		SET @v_result = 1
		SELECT @v_result AS [status], @po_message AS [message]  -- dual output stored procedure, variable output dan table output
		GOTO CLEAN_OUT

	END TRY
	BEGIN CATCH	-- tangkap error message selain yg sudah dideskripsikan
		SET @po_message = LEFT(ERROR_MESSAGE(),400)	-- berhubung variable diatas diset 400, maka potong error message
		GOTO ERROR_OUT
	END CATCH

	
	ERROR_OUT: 
		ROLLBACK TRANSACTION
		SELECT @v_result AS [status], @po_message AS [message]  -- dual output stored procedure, variable output dan table output
		--RETURN 1

	CLEAN_OUT:
		--RETURN 0
			

END
GO
