0

我有当前的代码,

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 的下划线

4

2 回答 2

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
于 2012-12-05T19:54:27.683 回答
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 函数来创建新字符串。

于 2012-12-05T20:34:36.937 回答