﻿USE [FabApprovalSystem]
GO
	/****** Object:  StoredProcedure [dbo].[_8DGetEmailListClosureNotification]    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].[_8DGetEmailListClosureNotification] -- Add the parameters for the stored procedure here
	@DocID 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
SELECT
	U.Email
FROM
	Users U
	INNER JOIN _8DCorrectiveAction CA ON CA.D1AssigneeID = U.userID
WHERE
	CANo = @DocID
UNION
SELECT
	U.Email
FROM
	Users U
	INNER JOIN _8DCorrectiveAction CA ON CA.RequestorID = U.userID
WHERE
	CANo = @DocID
UNION
SELECT
	U.Email
FROM
	Users U
	INNER JOIN _8DCorrectiveAction CA ON CA.QAID = U.userID
WHERE
	CANo = @DocID
UNION
SELECT
	U.Email
FROM
	Users U
	INNER JOIN _8DCorrectiveAction CA ON CA.RequestorID = U.userID
WHERE
	CANo = @DocID
UNION
SELECT
	Email
FROM
	SubRoleCategory SRC
	INNER JOIN SubRole SR ON SRC.SubRoleCategoryID = SR.SubRoleCategoryID
	INNER JOIN UserSubRole USR ON SR.SubRoleID = USR.SubRoleID
	INNER JOIN Users U ON USR.UserID = U.UserID
WHERE
	SRC.SubRoleCategoryItem = 'Quality / Probe'
END
GO