32 lines
929 B
Transact-SQL
32 lines
929 B
Transact-SQL
USE [FabApprovalSystem]
|
|
GO
|
|
/****** Object: UserDefinedFunction [dbo].[fnGetScrapCount] 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].[fnGetScrapCount] (
|
|
-- Add the parameters for the function here
|
|
@IssueID INT
|
|
) RETURNS INT AS BEGIN -- Declare the return variable here
|
|
DECLARE @ScrapCount INT -- Add the T-SQL statements to compute the return value here
|
|
SELECT
|
|
@ScrapCount = SUM(ScrapCount)
|
|
FROM
|
|
LotDisposition LD
|
|
INNER JOIN Lot L ON LD.IssueID = L.IssueID
|
|
INNER JOIN ScrapLot S ON L.IssueID = S.IssueID
|
|
AND L.LotNumber = S.LotNo
|
|
WHERE
|
|
LD.IssueID = @IssueID
|
|
AND ScrapCount > 0 -- Return the result of the function
|
|
RETURN @ScrapCount
|
|
END
|
|
GO |