最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

sql通過日期判斷年齡函數(shù)的示例代碼

 更新時間:2021年07月15日 16:12:19   作者:kueizheng  
這篇文章主要介紹了sql通過日期判斷年齡函數(shù),本文通過示例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

定義函數(shù):

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

使用函數(shù):

到此這篇關(guān)于sql通過日期判斷年齡函數(shù)的示例代碼的文章就介紹到這了,更多相關(guān)sql日期計算年齡內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

石河子市| 壤塘县| 九台市| 平南县| 镇江市| 南开区| 海口市| 林周县| 枣庄市| 天祝| 乳源| 宝丰县| 临高县| 定南县| 高台县| 开阳县| 博野县| 邹城市| 绵阳市| 武胜县| 抚松县| 砚山县| 天柱县| 武鸣县| 邵东县| 寻甸| 吉水县| 厦门市| 怀远县| 日土县| 永春县| 广平县| 边坝县| 西平县| 望城县| 巴楚县| 和顺县| 沙坪坝区| 疏附县| 荆门市| 博湖县|