我想计算从这个人出生到今天的年数.我有要使用的组件,但不知道如何使用它们.
I want to count the amount of years from a the year the person is born to today. I have the components to use but dont know how to use them.
SELECT COLUMN1, COLUMN2, DATEPART(YY,GETDATE()),
CONVERT(INT,+19)))LEFT(TABLE.COLUMN,2)
我想用 +19 在出生年之前显示它.例如,在数据库中,出生年份显示为 YY 而不是 YYYY.这就是为什么我要添加 19,所以 SQL 将计算从 19YY 到 2013 的年数.
I want to use the +19 to show it before the birtyear. Example in the database the birthyear is showed as YY not YYYY. That is why I want to add the 19, so the SQL will count years from 19YY to 2013.
试试这个
SELECT id
, Name
, DATEDIFF(yy, CONVERT(DATETIME, DOB), GETDATE()) AS AGE
, DOB
FROM MyTable
这篇关于从某个日期开始计算年数 SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
修改现有小数位信息Modify Existing decimal places info(修改现有小数位信息)
多次指定相关名称“CONVERT"The correlation name #39;CONVERT#39; is specified multiple times(多次指定相关名称“CONVERT)
T-SQL 左连接不返回空列T-SQL left join not returning null columns(T-SQL 左连接不返回空列)
从逗号或管道运算符字符串中删除重复项remove duplicates from comma or pipeline operator string(从逗号或管道运算符字符串中删除重复项)
将迭代查询更改为基于关系集的查询Change an iterative query to a relational set-based query(将迭代查询更改为基于关系集的查询)
将零连接到 sql server 选择值仍然显示 4 位而不是concatenate a zero onto sql server select value shows 4 digits still and not 5(将零连接到 sql server 选择值仍然显示 4 位而不是 5)