﻿USE [FabApprovalSystem]
GO
	/****** Object:  StoredProcedure [dbo].[MRBLogHoldFlagSentToSPNHistory]    Script Date: 11/21/2024 11:29:05 AM ******/
SET
	ANSI_NULLS ON
GO
SET
	QUOTED_IDENTIFIER ON
GO
	CREATE PROCEDURE [dbo].[MRBLogHoldFlagSentToSPNHistory] -- Add the parameters for the stored procedure here
	@MRBNumber INT AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
SET
	NOCOUNT ON;

-- Insert statements for procedure here
INSERT INTO
	MRBLotsToBeSentToSPNHistory (
		LotNumber,
		MRBNumber,
		DispoType,
		AddRemoveMRBFlag
	)
SELECT
	LotNumber,
	MRBNumber,
	DispoType,
	AddRemoveChangeMRBFlag
FROM
	MRBLotsToBeSentToSPN
WHERE
	MRBNumber = @MRBNumber
	AND IsDirty = 1
UPDATE
	MRBLotsToBeSentToSPN
SET
	IsDirty = 0,
	SentToSPN = 1,
	MRBLotLastSentToSPNDatetime = GETDATE()
WHERE
	MRBNumber = @MRBNumber
	AND IsDirty = 1
END
GO