select rtrim((datediff(month,0,getdate())-datediff(month,0,'2000-7-1'))/12)+'年'+rtrim((datediff(month,0,getdate())-datediff(month,0,'2000-7-1'))%12)+'月'

解决方案 »

  1.   

    --上面的放弃,LZ的那个算法是Execel下的算法,SQL里当然不可以用
    --改一下
    select year(getdate())-year(满试日期)-1 + case when month(getdate)>=month(满试日期) then 1 else 0 end
      

  2.   

    --视图里就是下面这样,不要随便把Excel的语法通过用来select ......
    (year(getdate())-year(满试日期)-1 + case when month(getdate)>=month(满试日期) then 1 else 0 end)as 
    工龄
    from ...........