1

我的查询是将 varchar 转换为字符串,

select top(5)'Insert into jobs(minexperience,maxexperience)values('+

cast(substring(Experience as varchar(50)),0,patindex('%to%',Experience))*365*24*60*60,

cast(substring(Experience as      

varchar(50)),patindex('%to%',Experience)+2,patindex('%Years%',Experience)-patindex('%to%',Experience)-2)*365*24*60*60+')'

from requirementsdetailsfororganization

在下面的查询中,我有一个错误“关键字'AS'附近的语法不正确。”

我想将字符串转换为整数。

有什么帮助吗?

4

1 回答 1

2

可能这对您有帮助-

SELECT TOP(5) 'INSERT INTO dbo.jobs(minexperience,maxexperience) VALUES(' +
    CAST(SUBSTRING(
          CAST(r.Experience AS VARCHAR(50))
        , 0
        , r.ToExperience) * 31536000 
    AS VARCHAR(50))

    + ',' +

    CAST(SUBSTRING(
          CAST(r.Experience AS VARCHAR(50))
        , r.ToExperience + 2
        , patindex('%Years%', r.Experience) - r.ToExperience - 2) * 31536000 
    AS VARCHAR(50))
+')'
FROM (
    SELECT 
          r.Experience
        , ToExperience = PATINDEX('%to%', r.Experience)
    FROM dbo.requirementsdetailsfororganization r
) r
于 2013-04-17T06:06:01.493 回答