0
我已經創建了下面的函數,並且它似乎隨機將@FCST和@QTY值更改爲隨機選擇。下面是調試中返回錯誤值爲@FCST的程序示例。由於@FCST在9.53,我預計它會返回9.53。 SQL函數 - 將變量設置爲隨機值
CREATE FUNCTION dbo.LTBADJ
(@MAT VARCHAR(30),@LCUT DATE, @QS DATE,@STAT FLOAT, @MCA FLOAT)
RETURNS FLOAT
AS BEGIN
DECLARE @HD DATE
DECLARE @ED DATE
DECLARE @FCST FLOAT
DECLARE @QTY FLOAT
DECLARE @YRS FLOAT
SET @ED =
(SELECT TOP 1 [EO_END_DATE] FROM [dbo].[EO_LTB]
WHERE [W_PART_NUMBER] = @MAT
AND [APPROVED_DATE] <= @LCUT
ORDER BY [EO_END_DATE] DESC)
SET @HD =DATEADD(YEAR,2,@QS)
SET @FCST = (CASE WHEN @MCA <= @STAT THEN @MCA ELSE @STAT END)
SET @FCST = (CASE WHEN @FCST <.5 THEN .5 ELSE @FCST END)
SET @YRS = (DATEDIFF(DAY,@HD,@ED) + 730)/365
SET @QTY = @FCST * @YRS
SET @QTY = (CASE WHEN @ED<[email protected] THEN 0 ELSE @QTY END)
RETURN @QTY
END ;
編輯:@QTY的實例計算錯誤
嗯...這不是'9.53' ..這'9.53×10^-2' ='9.53 X 0.01' ..這是0.0953 – 2014-11-24 21:52:09
並且結果是'5×10^-1' ='5 x 0.1' ='0.5' ..這就是你指定它的時候少於0.5 – 2014-11-24 21:53:50
在你的更新中,QTY是'21.345 +'..應該是什麼? – 2014-11-24 21:58:41