SQL 年 月 日 分开后最后组装成时间处理办法

在项目一开始存储时间把时间分开年,月,日3个字段,没有保存具体的时间,现在需要组装成时间格式参与查询。

现将处理办法做一个整理,以便后期查询,也方便大家

declare @year int
declare @month int
declare @day int

set @year = 2022
set @month = 3
set @day = 16

-- 现组装成时间格式
select replace(cast(@year+@month*0.01 as char(7)),'.','-')+replace(cast(@day * 0.01 as char(4)),'0.','-') time

个人博客地址:SQL server 年 月 日 分开后最后组装成时间处理办法-白雨青工作站

猜你喜欢

转载自blog.csdn.net/qq_41674785/article/details/123519027