2013-04-16 55 views
1
在SELECT語句詮釋

我的查詢是將varchar轉換成字符串,將varchar轉換到使用PATINDEX

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’附近有語法錯誤。」

我想將字符串轉換爲整數。

任何幫助?

+0

ü要轉換的經驗作爲字符串 –

+1

你必須選擇演員和子功能。 – dferidarov

+0

dferidarov:怎麼樣? – PoliDev

回答

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 
+0

它運作良好。 – PoliDev