--函数
create function f_Y(@X decimal(18,2))
returns decimal(18,2)
as
begin
declare @Y decimal(18,2)
if @X<10
SET @Y=@X*0.05
ELSE IF @X>=10 and @X<100
SET @Y=(@X-10)*0.03+10*0.05
ELSE IF @X>=100 and @X<1000
SET @Y=(@X-100)*0.01+90*0.03+10*0.05
RETURN(@Y)
END
GO--调用
select dbo.f_Y(10)
create function f_Y(@X decimal(18,2))
returns decimal(18,2)
as
begin
declare @Y decimal(18,2)
if @X<10
SET @Y=@X*0.05
ELSE IF @X>=10 and @X<100
SET @Y=(@X-10)*0.03+10*0.05
ELSE IF @X>=100 and @X<1000
SET @Y=(@X-100)*0.01+90*0.03+10*0.05
RETURN(@Y)
END
GO--调用
select dbo.f_Y(10)
returns decimal(18,2)
as
begin
RETURN(CASE
WHEN @x<10 then @x*0.05
WHEN @x>=10 and @x<100 then (@x-10)*0.03+10*0.05
WHEN @x>=100 and @x<1000 then (@x-100)*0.01+90*0.03+10*0.05
END)
END
GO--调用
select dbo.f_Y(10)