select a,case when datepart(day,B)<=datepart(day,getdate()) then datediff(month,B,getdate()) else datediff(month,B,getdate())+1 end as b from tablename
呵呵,错了select a,case when datepart(day,B)<=datepart(day,getdate()) then datediff(month,B,getdate()) else datediff(month,B,getdate())-1 end as b from tablename
from tablename
from tablename