﻿USE [FabApprovalSystem]
GO
	/****** Object:  StoredProcedure [dbo].[LTRestoreLotTravToPrevRevision]    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].[LTRestoreLotTravToPrevRevision] @PrevLotTravelerRevisionID INT,
	@NewLotTravelerRevisionID INT AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	DECLARE @PrevRevisionNumber INT DECLARE @LotID INT
SELECT
	@PrevRevisionNumber = RevisionNumber,
	@LotID = LTLotID
FROM
	LTLotTravelerRevisionAttrib
WHERE
	ID = @PrevLotTravelerRevisionID
DELETE FROM
	LTLotTravelerHoldSteps
WHERE
	LotTravelerRevisionID = @NewLotTravelerRevisionID
DELETE FROM
	LTLotTravAttachment
WHERE
	LotTravelerRevisionID = @NewLotTravelerRevisionID
DELETE FROM
	LTLotTravelerRevisionAttrib
WHERE
	ID = @NewLotTravelerRevisionID
UPDATE
	LTLotTravelerRevisionAttrib
SET
	IsCurrentRevision = 1
WHERE
	ID = @PrevLotTravelerRevisionID
UPDATE
	LTLot
SET
	LotTravelerCurrentRevision = @PrevRevisionNumber
WHERE
	ID = @LotID
END
GO