CREATE FUNCTION dbo.Function1 
(@str varchar(20))   --申请号
RETURNS int
AS
begin
        declare @p int   --返回专利应缴费金额
declare @cha  int   --距现在的年份差
declare @dd  datetime   --目前日期
select @dd = output from v_getdate
if left(@str,1)='2' set @cha=(cast(year(@dd) as int)-cast(left(@str,4) as int)
         else set @cha=(cast(year(@dd) as int)-cast('19'+left(@str,2) as int))
 if (left(@str,1)='2' and substring(@str,5,1)='1' or left(@str,1)<>'2' and substring(@str,3,1)='2')
 begin 
 if @cha in (1,2,3)
 set @p=900
 else if @cha in (4,5,6)
 set @p=1200
 else if @cha in (7,8,9)
 set @p=2000
 else if @cha in (10,11,12)
 set @p=4000
 else if @cha in (13,14,15)
 set @p=6000
 else if @cha in (16, 17, 18, 19, 20)
  set @p=8000
  Else
  set  @p=0
 end
 
 else
 begin
 if @cha in (1,2,3)
 set @p=600
 else if @cha in (4,5)
 set @p=900
 else if @cha in (6,7,8)
 set @p=1200
 else if @cha in (9,10)
 set @p=2000 
 else   set @p=0
         end
return @p
end