[英]Extracting year and month from datekey in my sql
I have a datekey column in my database.我的数据库中有一个 datekey 列。 I want to extract Year and Month from it.
我想从中提取年和月。
Datekey column
20140101
20151223
20140809
20201201
Assuming these are numbers, use numeric operations:假设这些是数字,请使用数字运算:
select floor(datekey / 10000) as year,
(datekey / 100) % 100 as month,
datekey % 100 as day
You can try the below -你可以试试下面的——
select month(convert(datekey,char)) as mon,
year(convert(datekey,char)) as yr
from tablename
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.