0

私のテーブルには、次のような経験フィールドがあります

経験

  • 5年0ヶ月

  • 2年0ヶ月

ここでは、秒に変換してから、年と月を 1 つの列に追加します。

経験 - [ある程度の価値]

したがって、次のようなクエリを1つ作成します。

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)

私のクエリでそれを行う方法は?誰か助けて?

4

2 に答える 2

1

私は答えを見つけた、

SELECT TOP(10) 'INSERT INTO jobs(Experience) VALUES('+
        CAST(SUBSTRING(CAST(r.experience AS VARCHAR(50)), 0, PATINDEX('%Years%', r.experience))*31536000
            + SUBSTRING(CAST(r.experience AS VARCHAR(50)), PATINDEX('%Years%', r.experience) + 5, 
                                                       patindex('%Months%', r.Experience) - PATINDEX('%Years%', r.Experience) - 5)* 2678400 AS VARCHAR(50))+')'
    FROM  candidatedetails r
于 2013-04-20T11:18:46.727 に答える
1

あなたが望むのは、このようなものを回すことです(現在生成されています)

insert into candidates(experience)values(157680000,0)
insert into candidates(experience)values(31536000,26784000)

これに、それらを合計します

insert into candidates(experience) select 157680000+0;
insert into candidates(experience) select 31536000+26784000;

元のコードを同様に変更するように見えます:

select top(10) 'insert into candidates(experience) select '+
        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
于 2013-04-20T11:13:08.197 に答える