Add values show into single column in sql server -
in table, have experience field like
experience
5years0months
2years0months
here want convert seconds add years , months single column.
experience - [some value]
so create 1 query following,
select top(10)'insert candidates(experience)values('+ cast(substring(cast(o.experience varchar(50)), 0, patindex('%years%', o.experience)) * 31536000 varchar(50)) +','+cast(substring(cast(o.experience varchar(50)), patindex('%years%', o.experience) + 5 ,patindex('%months%', o.experience) - patindex('%years%', o.experience) - 5) * 2678400 varchar(50))+')' candidatedetails o
from above code have result like,
experience
insert candidates(experience)values(157680000,0) insert candidates(experience)values(31536000,26784000)
expected result
insert candidates(experience)values(157680000) insert candidates(experience)values(58320000)//add(31536000+26784000)
how in query? me anyone?
what want turn (currently generated)
insert candidates(experience)values(157680000,0) insert candidates(experience)values(31536000,26784000)
to this, sum them
insert candidates(experience) select 157680000+0; insert candidates(experience) select 31536000+26784000;
which looks changing original code similarly:
select top(10) 'insert candidates(experience) select '+ cast(substring(cast(o.experience varchar(50)), 0, patindex('%years%', o.experience)) * 31536000 varchar(50)) +'+'+cast(substring(cast(o.experience varchar(50)), patindex('%years%', o.experience) + 5, patindex('%months%', o.experience) - patindex('%years%', o.experience) - 5) * 2678400 varchar(50))+';' candidatedetails o
Comments
Post a Comment