在我的表中,我有经验字段,例如
经验
5年0个月
2年0个月
在这里,我想转换为秒,然后将年份和月份添加到单个列中。
经验 - [一些价值]
所以我创建了一个如下查询,
select top(10)'insert into candidates(experience)values('+
CAST(SUBSTRING(CAST(o.Experience AS VARCHAR(50)), 0, PATINDEX('%Years%', o.Experience)) * 31536000 AS VARCHAR(50))
+','+CAST(SUBSTRING(CAST(o.Experience AS VARCHAR(50)), PATINDEX('%Years%', o.Experience) + 5
,patindex('%Months%', o.Experience) - PATINDEX('%Years%', o.Experience) - 5) *
2678400 AS VARCHAR(50))+')'
from candidatedetails as o
从上面的代码我得到的结果是,
经验
insert into candidates(experience)values(157680000,0)
insert into candidates(experience)values(31536000,26784000)
预期结果
insert into candidates(experience)values(157680000)
insert into candidates(experience)values(58320000)//add(31536000+26784000)
如何在我的查询中做到这一点?有人帮我吗?