2012-12-05 54 views
0

我當前的代碼,上更新語句MySQL的語法錯誤

UPDATE i 
SET LeadInventor = 
    CASE 
     WHEN gs.FirstInventorName IS NULL THEN 'No' 
     ELSE 'Yes' 
    END 
FROM patentdb.Inventor i 
    LEFT JOIN patentdb.generalsource gs 
    ON i.InventorFirst + ' ' + i.InventorLast = gs.FirstInventorName 

,我不明白爲什麼它會引發以下錯誤:

Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM patentdb.Inventor i  LEFT JOIN patentdb.generalsource gs  ON i.Invent' at line 7 

的FROM語句是什麼MySQL是強調

回答

1

這是因爲FROM子句在MySQL UPDATE語句中無效:

http://dev.mysql.com/doc/refman/5.6/en/update.html

你可能有更好的運氣與此:

UPDATE Inventor i, generalsource gs 
SET i.LeadInventor = CASE 
    WHEN gs.FirstInventorName IS NULL THEN 'No' 
    ELSE 'Yes' 
END 
WHERE i.InventorFirst + ' ' + i.InventorLast = gs.FirstInventorName 
0

語法不正確。看看這個查詢:

UPDATE patentdb.Inventor i 
    LEFT JOIN patentdb.generalsource gs 
    ON CONCAT(i.InventorFirst, ' ', i.InventorLast) = gs.FirstInventorName 
SET LeadInventor = 
    CASE WHEN gs.FirstInventorName IS NULL THEN 'No' ELSE 'Yes' END 

另外,我想說,在MySQL中最好使用CONCAT函數來創建新的字符串。