﻿USE [FabApprovalSystem]
GO
	/****** Object:  StoredProcedure [dbo].[MRBUpdateSPNMRBHoldFlagReport_PriorValues]    Script Date: 11/21/2024 11:29:05 AM ******/
SET
	ANSI_NULLS ON
GO
SET
	QUOTED_IDENTIFIER ON
GO
	-- =============================================
	-- Author:		<Author,,Name>
	-- Create date: <Create Date,,>
	-- Description:	<Description,,>
	-- =============================================
	CREATE PROCEDURE [dbo].[MRBUpdateSPNMRBHoldFlagReport_PriorValues] @MRBNumber INT,
	@MRBHoldFlagReportAttrTable dbo.udtMRBHoldFlagReportUpdateTable READONLY AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
SET
	NOCOUNT ON;

DECLARE @ErrorMessage NVARCHAR(4000);

DECLARE @ErrorSeverity INT;

DECLARE @ErrorState INT;

-- Insert statements for procedure here
BEGIN TRY BEGIN TRAN
UPDATE
	M
SET
	PriorMRB_DispoType = T.PriorMRB_DispoType,
	PriorMRBHoldLocation = T.PriorMRBHoldLocation,
	PriorMRBHoldOperation = T.PriorMRBHoldOperation
FROM
	MRBHoldFlagReport M
	INNER JOIN @MRBHoldFlagReportAttrTable T ON M.MRBNumber = T.MRBNumber
	AND M.LotNo = T.LotNo EXEC MRBInsertSplitLotsNotInMRB_HoldFlagReportTable @MRBNumber COMMIT TRAN
END TRY BEGIN CATCH ROLLBACK
SELECT
	@ErrorMessage = ERROR_MESSAGE() + CONVERT(VARCHAR(10), @MRBNumber),
	@ErrorSeverity = ERROR_SEVERITY(),
	@ErrorState = ERROR_STATE();

RAISERROR (
	@ErrorMessage,
	-- Message text.
	@ErrorSeverity,
	-- Severity.
	@ErrorState -- State.
);

END CATCH
END
GO