下載吧 - 綠色安全的游戲和軟件下載中心

          軟件下載吧

          當前位置:軟件下載吧 > 數據庫 > MS_SQL > SQL基礎:sql通過日期判斷年齡函數的示例代碼

          SQL基礎:sql通過日期判斷年齡函數的示例代碼

          時間:2024-03-08 08:50作者:下載吧人氣:31

          定義函數:

          CREATE FUNCTION [dbo].[GetAge]
          (
          @BirthDay nvarchar(20) –生日
          )
          RETURNS varchar(20)
          AS
          BEGIN
          if(@BirthDay is NUlL or @BirthDay=”)
          return ”;
          — Declare the return variable here
          DECLARE @age varchar(20)
          DECLARE @years int
          DECLARE @months int
          DECLARE @days int
          — Add the T-SQL statements to compute the return value here
          set @age = ”

          set @years = year(GETDATE()) – year(@birthday)
          set @months = month(GETDATE()) – month(@birthday)
          if day(@birthday)<=day(GETDATE())
          set @days = day(GETDATE()) – day(@birthday)
          else
          begin
          set @months = @months – 1
          if MONTH(@birthday) in (1,3,5,7,8,10,12)
          set @days = 31-day(@birthday)+day(GETDATE())
          else if MONTH(@birthday) in (4,6,9,11)
          set @days = 30-day(@birthday)+day(GETDATE())
          else if MONTH(@birthday) = 2
          if (year(@birthday)%4 = 0 and year(@birthday)%100 <> 0) or year(@birthday)%400 = 0
          set @days = 29-day(@birthday)+day(GETDATE())
          else
          set @days = 28-day(@birthday)+day(GETDATE())
          end
          if @months < 0
          begin
          set @years = @years – 1
          set @months = @months + 12
          end
          if @years = 0 and @months = 0
          begin
          return convert(varchar,@days+1) + ‘天’
          end
          if @years > 0
          set @age = cast(@years as varchar(5)) + ‘歲’
          if @years < 3 and @months > 0 and @years>-1
          begin
          set @age = @age + cast(@months as varchar(5)) + ‘月’
          end
          if @years<0
          set @age=”
          RETURN @age
          END

          標簽MSSQL,SQLServer,技術文檔,數據庫,SQLSERVER

          相關下載

          查看所有評論+

          網友評論

          網友
          您的評論需要經過審核才能顯示

          熱門閱覽

          最新排行

          公眾號

          主站蜘蛛池模板: 人妻无码一区二区不卡无码av| 国产日韩高清一区二区三区| 亚洲av区一区二区三| 一区二区三区美女视频| 国模吧一区二区三区| 国产一区二区三区在线免费观看| 国产精品综合一区二区三区| 国产一区二区免费| 精品一区二区三区在线观看l | 视频一区在线播放| 亚洲国产一区二区视频网站| 在线视频一区二区| 久久亚洲色一区二区三区| 精品永久久福利一区二区| 精品乱人伦一区二区三区| 一区二区三区免费视频网站| 国产吧一区在线视频| 久久久久人妻一区精品性色av| 视频一区二区三区免费观看| 精品国产一区二区三区av片| 亚洲高清美女一区二区三区| 久久无码人妻一区二区三区 | 精品人妻少妇一区二区三区在线| 成人免费视频一区| 激情久久av一区av二区av三区| 午夜性色一区二区三区免费不卡视频| 国产一区二区三区不卡AV| 国产精品丝袜一区二区三区 | 国产精品熟女一区二区| 亚洲毛片αv无线播放一区| 中文字幕精品亚洲无线码一区应用| 亚洲AV永久无码精品一区二区国产| 无码AV一区二区三区无码| 成人精品视频一区二区三区| 精品一区二区三区高清免费观看 | 亚洲AV无码一区二区三区在线| 无码乱码av天堂一区二区 | 亚洲AV成人一区二区三区AV| 亚洲福利秒拍一区二区| 视频一区二区三区在线观看| 国产一在线精品一区在线观看|