50 lines
1.3 KiB
Transact-SQL
50 lines
1.3 KiB
Transact-SQL
USE [FabApprovalSystem]
|
|
GO
|
|
/****** Object: UserDefinedFunction [dbo].[fn_Get8DCASectionByUser] Script Date: 11/21/2024 11:31:55 AM ******/
|
|
SET
|
|
ANSI_NULLS ON
|
|
GO
|
|
SET
|
|
QUOTED_IDENTIFIER ON
|
|
GO
|
|
-- =============================================
|
|
-- Author: <Author,,Name>
|
|
-- Create date: <Create Date,,>
|
|
-- Description: <Description,,>
|
|
-- =============================================
|
|
CREATE FUNCTION [dbo].[fn_Get8DCASectionByUser] (
|
|
-- Add the parameters for the function here
|
|
@UserID INT
|
|
) RETURNS TABLE AS RETURN (
|
|
-- Add the SELECT statement with parameter references here
|
|
-- M_Suffix
|
|
SELECT
|
|
DISTINCT 'CorrectiveAction' AS DocumentType,
|
|
'CA' AS SubDoc,
|
|
*
|
|
FROM
|
|
(
|
|
SELECT
|
|
DISTINCT CA.CANo as IssueID,
|
|
CA.CANo as DocID,
|
|
CA.IssueDate,
|
|
'' AS LotNos,
|
|
'' AS 'PendingApprovers',
|
|
CONCAT(A.DSection, ' Approval', ' - ', CA.CATitle) AS Title,
|
|
'' AS 'IssueDescription',
|
|
U2.FirstName + ' ' + U2.LastName AS Originator,
|
|
A.DateAssigned AS SubmitedDate,
|
|
'' AS CloseDate,
|
|
'' AS ItemStatus,
|
|
NULL AS NextDueDate
|
|
FROM
|
|
_8DCorrectiveAction CA
|
|
INNER JOIN _8DSectionApproval A ON A.CaNo = CA.CANo
|
|
LEFT JOIN Users U2 ON CA.RequestorID = U2.UserID
|
|
WHERE
|
|
A.Approved IS NULL
|
|
AND A.UserId = @UserID
|
|
AND CA.Deleted = 0
|
|
) AS A
|
|
)
|
|
GO |