易飞自定义SQL自定义月结日期取月份函数

来源:互联网 发布:宁南山 知乎 编辑:程序博客网 时间:2024/06/07 03:17
ALTER function Fun_Date(@Date char(2),@dates DATETIME ) returns char(2)--输入月结天数,送货日期
as
--给出日期计算月结数函数,
 begin
       
      declare  @RtDate char(12)

         if(convert(int,@Date)<>31)

--先加一个月再减去天数

         set @RtDate=DATENAME(MM,dateadd(DD,-convert(int,@Date),DATEADD(MM,1,@dates)))
          else  
          set @RtDate=DATENAME(MM,@dates)

          return @RtDate
      end

0 0