--drop function [get_Fee] SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO create function [dbo].[get_Fee](@Contractno varchar(50),@Feename varchar(50),@Feetype tinyint) returns numeric(18,2) as begin declare @S numeric(18,2) select @S=( select sum(cf.amount) from ch_fee cf where cf.bsno=@Contractno and cf.feename=@Feename and cf.feetype=@Feetype) if @s is null set @s=0 return @S end GO select dbo.[get_Fee]('XXH201311180001','β¿î',1) select * from ch_fee