FormatDate 用户自定义的一个函数!create function [dbo].[FormatDate]
FormatDate 用户自定义的一个函数!     (
FormatDate 用户自定义的一个函数!     
@dDate datetime          --Date value to be formatted
FormatDate 用户自定义的一个函数!
     ,@sFormat varchar(40)    --Format for date value
FormatDate 用户自定义的一个函数!
     )
FormatDate 用户自定义的一个函数!
returns varchar(40)
FormatDate 用户自定义的一个函数!
as
FormatDate 用户自定义的一个函数!
begin
FormatDate 用户自定义的一个函数!
FormatDate 用户自定义的一个函数!     
-- Insert the Month
FormatDate 用户自定义的一个函数!
     -- ~~~~~~~~~~~~~~~~
FormatDate 用户自定义的一个函数!
     set @sFormat = replace(@sFormat,'MMMM',datename(month,@dDate))
FormatDate 用户自定义的一个函数!     
set @sFormat = replace(@sFormat,'MMM',convert(char(3),datename(month,@dDate)))
FormatDate 用户自定义的一个函数!     
set @sFormat = replace(@sFormat,'MM',right(convert(char(4),@dDate,12),2))
FormatDate 用户自定义的一个函数!     
set @sFormat = replace(@sFormat,'M1',convert(varchar(2),convert(int,right(convert(char(4),@dDate,12),2))))
FormatDate 用户自定义的一个函数!
FormatDate 用户自定义的一个函数!     
-- Insert the Day
FormatDate 用户自定义的一个函数!
     -- ~~~~~~~~~~~~~~
FormatDate 用户自定义的一个函数!
     set @sFormat = replace(@sFormat,'DDDD',datename(weekday,@dDate))
FormatDate 用户自定义的一个函数!     
set @sFormat = replace(@sFormat,'DDD',convert(char(3),datename(weekday,@dDate)))
FormatDate 用户自定义的一个函数!     
set @sFormat = replace(@sFormat,'DD',right(convert(char(6),@dDate,12),2))
FormatDate 用户自定义的一个函数!     
set @sFormat = replace(@sFormat,'D1',convert(varchar(2),convert(int,right(convert(char(6),@dDate,12),2))))
FormatDate 用户自定义的一个函数!
FormatDate 用户自定义的一个函数!     
-- Insert the Year
FormatDate 用户自定义的一个函数!
     -- ~~~~~~~~~~~~~~~
FormatDate 用户自定义的一个函数!
     set @sFormat = replace(@sFormat,'YYYY',convert(char(4),@dDate,112))
FormatDate 用户自定义的一个函数!     
set @sFormat = replace(@sFormat,'YY',convert(char(2),@dDate,12))
FormatDate 用户自定义的一个函数!
FormatDate 用户自定义的一个函数!     
-- Return the function's value
FormatDate 用户自定义的一个函数!
     -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~  
FormatDate 用户自定义的一个函数!
     return @sFormat
FormatDate 用户自定义的一个函数!
end
FormatDate 用户自定义的一个函数!
FormatDate 用户自定义的一个函数!
FormatDate 用户自定义的一个函数!
FormatDate 用户自定义的一个函数!
FormatDate 用户自定义的一个函数!

相关文章:

  • 2021-12-03
  • 2021-05-15
  • 2021-12-27
  • 2022-12-23
  • 2022-02-08
  • 2021-11-23
  • 2021-05-08
  • 2021-11-12
猜你喜欢
  • 2021-06-26
  • 2021-08-19
  • 2021-07-11
  • 2021-08-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案