sql用户自定义标量值函数
创建函数
CREATE FUNCTION [dbo].[GetWeightCharge] ( @cemskind VARCHAR(30)--渠道 ,@classsif TINYINT --区间分类 ,@variate DECIMAL(18,3) --数值大小 ,@faddons DECIMAL(18,4) --燃油汇率 ) RETURNS DECIMAL(18,2)--返回值 AS BEGIN DECLARE @charge DECIMAL(18,2) ,@isfuel BIT --0:不加收;1:加收燃油 SELECT TOP 1 @charge=charges,@isfuel=isfuel FROM dbo.op_weight_cemskind_charge WHERE cemskind=@cemskind AND classsif=@classsif AND @variate BETWEEN begindata AND enddata SET @charge = ISNULL(@charge, 0.00) IF(@isfuel=1) BEGIN SET @charge=@charge + @charge*(ISNULL(@faddons,0.0000))/100 END RETURN ISNULL(@charge, 0.00) END GO
返回值只能只有一个
调用方式
select dbo.GetWeightCharge(@cemskind,0,ilong,@faddons)