﻿USE [FabApprovalSystem]
GO
	/****** Object:  StoredProcedure [dbo].[CCInsertMeetingActionItem]    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].[CCInsertMeetingActionItem] @MeetingID INT,
	@ActionItemName VARCHAR(100),
	@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
INSERT INTO
	CCMeetingActionItem (MeetingID, ActionItemName, Gating, DueDate)
VALUES
	(@MeetingID, @ActionItemName, @Gating, @DueDate) DECLARE @MeetingActionItemID INT
SET
	@MeetingActionItemID = SCOPE_IDENTITY() 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 = @MeetingActionItemID
INSERT INTO
	CCMeetingActionItemResponsible
SELECT
	@MeetingActionItemID,
	ActionItemResponsible
FROM
	#tempTab
	DROP TABLE #tempTab
END
GO