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

軟件下載吧

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

SQL基礎(chǔ):sql通過日期判斷年齡函數(shù)的示例代碼

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

定義函數(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

標簽MSSQL,SQLServer,技術(shù)文檔,數(shù)據(jù)庫,SQLSERVER

相關(guān)下載

查看所有評論+

網(wǎng)友評論

網(wǎng)友
您的評論需要經(jīng)過審核才能顯示

熱門閱覽

最新排行

公眾號

主站蜘蛛池模板: 久久人妻无码中文字幕| 向日葵app看片视频| 九色综合九色综合色鬼| 日本免费色视频| 日本大乳高潮视频在线观看| 四虎网站1515hh四虎| 一本色道久久综合亚洲精品高清| 直接观看黄网站免费视频| 女人张腿让男桶免费视频大全| 亚洲精品乱码久久久久久按摩 | 亚洲色av性色在线观无码| 7777精品久久久大香线蕉| 桃子视频在线观看高清免费视频 | 亚洲成a人片毛片在线| 日本黄色小视频在线观看| 日本亚洲黄色片| 免费无码中文字幕A级毛片| 777xxxxx欧美| 日韩伦人妻无码| 公车校花小柔h| 8090在线观看免费观看| 日本香蕉一区二区三区| 再深点灬舒服了灬太大了乡村| 91酒店疯狂输出女神范范| 日韩美女拍拍免费视频网站| 和前辈夫妇交换性3中文字幕| 99re免费在线视频| 日韩精品一区二区三区在线观看| 又爽又黄又无遮挡网站| 77777亚洲午夜久久多喷| 日韩中文字幕免费视频| 免费无码一区二区三区蜜桃大| 2021国产麻豆剧果冻传媒入口| 日本在线观看一级高清片| 今天免费中文字幕视频| 黄色片在线播放| 好黄好猛好爽好痛的视频| 亚洲一区二区三区无码国产| 色视频在线观看免费| 在线91精品亚洲网站精品成人| 久久精品国产亚洲av成人|