质量水平
公式: 产出数 / (产出数 + 不良品数)
代码
CREATE FUNCTION [dbo].[udf_QualityLevel]
(
@OutputQuantity DECIMAL(18,6),
@DefectQuantity DECIMAL(18,6)
)
RETURNS DECIMAL(18,6)
AS
BEGIN
DECLARE @ReturnValue DECIMAL(18,6)
--计算总产出
DECLARE @GrossOutput DECIMAL(18,6)
SET @GrossOutput = (ISNULL(@OutputQuantity,0) + ISNULL(@DefectQuantity,0))
--计算质量水平
SELECT @ReturnValue=(CASE WHEN @GrossOutput = 0 THEN NULL WHEN @GrossOutput IS NULL THEN NULL WHEN @GrossOutput <> 0 THEN (ISNULL(@OutputQuantity,0) / @GrossOutput) END)
RETURN @ReturnValue
END
(
@OutputQuantity DECIMAL(18,6),
@DefectQuantity DECIMAL(18,6)
)
RETURNS DECIMAL(18,6)
AS
BEGIN
DECLARE @ReturnValue DECIMAL(18,6)
--计算总产出
DECLARE @GrossOutput DECIMAL(18,6)
SET @GrossOutput = (ISNULL(@OutputQuantity,0) + ISNULL(@DefectQuantity,0))
--计算质量水平
SELECT @ReturnValue=(CASE WHEN @GrossOutput = 0 THEN NULL WHEN @GrossOutput IS NULL THEN NULL WHEN @GrossOutput <> 0 THEN (ISNULL(@OutputQuantity,0) / @GrossOutput) END)
RETURN @ReturnValue
END