这个函数只是返回" 1"结果当我尝试用select选择结果时无论输入数字是什么。
Create Function dbo.LotValue (@IdAssetGroup as bit, @TdValueBase as real, @TdPrice as real, @IdRiskfactor as bit)
RETURNS real
as begin
DECLARE @Output AS real
set @Output =
(case
when @IdAssetGroup in (1, 8) then 1
when @IdAssetGroup in (2,3,4,6,7) then (@TdValueBase / @TdPrice)
when @IdAssetGroup in (5) then
Case @IdRiskfactor
when 8 then 1 --BLFT
else 0.01
end
when @IdAssetGroup in (9) then
case
when @IdRiskfactor in (1,42,84,113) then @TdValueBase --AUD, EUR,NZD,GBP
when @IdRiskfactor in (25,62) then (@TdValueBase / @TdPrice) --NDF: BRL, KRW
else (@TdValueBase / @TdPrice) *-1 --others FX
end
end)
return @Output;
end
它只是返回" 1":
select dbo.lotvalue(5,20,5,42)
答案 0 :(得分:4)
您每次都会遇到第一个案例(when @IdAssetGroup in (1, 8) then 1
),因为@IdAssetGroup
是bit
,只能是1或0。
你也和@IdRiskFactor
做同样的事情,我想这需要改变。我假设你希望这些是INT
s。
CREATE FUNCTION dbo.LotValue
(
@IdAssetGroup as INT,
@TdValueBase as real,
@TdPrice as real,
@IdRiskfactor as INT
)
RETURNS real
答案 1 :(得分:0)
这:@IdAssetGroup as bit
您可能需要int