﻿USE [FabApprovalSystem]
GO
	/****** Object:  StoredProcedure [dbo].[CCUpdateMeetingActionItem]    Script Date: 11/21/2024 11:29:04 AM ******/
SET
	ANSI_NULLS ON
GO
SET
	QUOTED_IDENTIFIER ON
GO
	-- =============================================
	-- Author:		<Author,,Name>
	-- Create date: <Create Date,,>
	-- Description:	<Description,,>
	-- =============================================
	CREATE PROCEDURE [dbo].[CCUpdateMeetingActionItem] @ID INT,
	@ActionItemName VARCHAR(500),
	--@ResponsiblePerson Varchar(50),
	@ResponsibleID Varchar(100),
	@Gating BIT,
	@DueDate DATETIME AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
SET
	NOCOUNT ON;

-- Insert statements for procedure here
UPDATE
	CCMeetingActionItem
SET
	ActionItemName = @ActionItemName,
	Gating = @Gating,
	DueDate = @DueDate
WHERE
	ID = @ID DECLARE @SEPERATOR as VARCHAR(1) DECLARE @SP INT DECLARE @VALUE VARCHAR(1000)
SET
	@SEPERATOR = ',' CREATE TABLE #tempTab (ActionItemResponsible int not null)
	WHILE PATINDEX('%' + @SEPERATOR + '%', @ResponsibleID) <> 0 BEGIN
SELECT
	@SP = PATINDEX('%' + @SEPERATOR + '%', @ResponsibleID)
SELECT
	@VALUE = LEFT(@ResponsibleID, @SP - 1)
SELECT
	@ResponsibleID = STUFF(@ResponsibleID, 1, @SP, '')
INSERT INTO
	#tempTab (ActionItemResponsible) VALUES (@VALUE)
END
DELETE FROM
	CCMeetingActionItemResponsible
WHERE
	MeetingActionItemID = @ID
INSERT INTO
	CCMeetingActionItemResponsible
SELECT
	@ID,
	ActionItemResponsible
FROM
	#tempTab
	DROP TABLE #tempTab
END
GO