探讨如何计算age的sql函数
时间:2024-01-21 12:44:31
ALTER FUNCTION [dbo].[get_FullAge]
(
@birthday datetime, @currentDay datetime
)
RETURNS INT
AS
BEGIN
DECLARE @age INT
SET @age = DATEDIFF(YEAR, @birthday, @currentDay)
IF DATEDIFF(DAY, DATEADD(YEAR, @age, @birthday), @currentDay) <= 0
SET @age = @age - 1
IF DATEPART(MONTH, @birthday) = 2 AND DATEPART(DAY, @birthday) = 29 AND DATEPART(MONTH, @currentDay) = 3
AND DATEPART(DAY, @currentDay) = 1 AND
NOT (YEAR(@currentDay) % 4 = 0 AND (YEAR(@currentDay) % 100 !=0 OR YEAR(@currentDay) % 400 = 0))
SET @age = @age - 1
IF @age < 0
SET @age = 0
RETURN @age
END
--Sql根据出生日期计算age(不是很准确)
1. select datediff(year,EMP_BIRTHDAY,getdate()) as '年龄' from EMPLOYEEUnChangeInfo
2. floor((DateDiff(day,u.EMP_BIRTHDAY,getdate()))/365
标签:age,sql函数
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python中的多重继承实例讲解
2022-06-18 01:51:05
![](https://img.aspxhome.com/file/2023/8/95568_0s.jpg)
Pandas中describe()函数的具体使用
2021-03-22 14:32:12
![](https://img.aspxhome.com/file/2023/6/99076_0s.jpg)
如何安装2019Pycharm最新版本(详细教程)
2022-09-19 12:20:54
![](https://img.aspxhome.com/file/2023/6/118356_0s.png)
JS定时器实例
2024-04-29 13:25:21
ASP代码中的容错机制
2008-10-19 17:30:00
Python模仿POST提交HTTP数据及使用Cookie值的方法
2022-05-04 04:37:35
golang 将[]byte转成16进制的实现
2024-02-17 00:35:03
Python定义一个跨越多行的字符串的多种方法小结
2022-08-04 03:34:27
![](https://img.aspxhome.com/file/2023/0/115070_0s.jpg)
MySQL主从同步原理介绍
2024-01-13 08:01:43
Python实现的本地文件搜索功能示例【测试可用】
2022-04-20 06:11:10
![](https://img.aspxhome.com/file/2023/2/111942_0s.png)
python flask 多对多表查询功能
2022-09-17 13:26:14
ASP中类的详细介绍(class Property Get、Property Let)
2008-02-20 19:18:00
Python专用方法与迭代机制实例分析
2021-09-07 22:05:22
用Python爬取某乎手机APP数据
2021-02-03 17:04:59
![](https://img.aspxhome.com/file/2023/3/118503_0s.png)
python网络爬虫 Scrapy中selenium用法详解
2023-02-03 06:08:46
![](https://img.aspxhome.com/file/2023/0/90690_0s.jpg)
python 使用openpyxl读取excel数据
2021-02-10 07:32:10
![](https://img.aspxhome.com/file/2023/0/130940_0s.png)
利用Python爬虫给孩子起个好名字
2022-04-25 23:40:29
![](https://img.aspxhome.com/file/2023/2/69422_0s.png)
使用Spring AOP实现MySQL数据库读写分离案例分析(附demo)
2024-01-16 04:47:03
![](https://img.aspxhome.com/file/2023/6/129246_0s.png)
基于Python实现千图成像工具的示例代码
2022-03-14 12:19:21
![](https://img.aspxhome.com/file/2023/5/93515_0s.png)
Python进阶之列表推导与生成器表达式详解
2022-01-18 00:07:04
![](https://img.aspxhome.com/file/2023/4/105734_0s.png)