db2:内部联接的SQL更新

时间:2014-07-25 21:29:41

标签: sql db2

我有这个选择SQL工作

SELECT O.* , S.NEW_EOC_CNTRT_SQ
FROM  FAMSUNIT.EOCT025_OPP_WRK O INNER JOIN
(
    SELECT A.EOC_CNTRT_SQ AS OLD_EOC_CNTRT_SQ, (SELECT B.EOC_CNTRT_SQ  
                FROM FAMSUNIT.EOCT020_CNTRT B 
                WHERE  B.ALIAS_CNTRT_ID = A.ALIAS_CNTRT_ID 
                AND CREA_USER_SQ IN (5,3) ) AS NEW_EOC_CNTRT_SQ
    FROM FAMSUNIT.EOCT020_CNTRT A       
    WHERE  A.ALIAS_CNTRT_ID IN ('12826')  
    AND CREA_USER_SQ NOT IN (5,3)
) S ON O.EOC_CNTRT_SQ = S.OLD_EOC_CNTRT_SQ

但是当我试图将其转换为更新语句时,我收到错误 -

UPDATE O
SET O.EOC_CNTRT_SQ = S.NEW_EOC_CNTRT_SQ
FROM  FAMSUNIT.EOCT025_OPP_WRK O INNER JOIN
(
    SELECT A.EOC_CNTRT_SQ AS OLD_EOC_CNTRT_SQ, (SELECT B.EOC_CNTRT_SQ  
                FROM FAMSUNIT.EOCT020_CNTRT B 
                WHERE  B.ALIAS_CNTRT_ID = A.ALIAS_CNTRT_ID 
                AND CREA_USER_SQ IN (5,3) ) AS NEW_EOC_CNTRT_SQ
    FROM FAMSUNIT.EOCT020_CNTRT A       
    WHERE  A.ALIAS_CNTRT_ID IN ('12826')  
    AND CREA_USER_SQ NOT IN (5,3)
) S ON O.EOC_CNTRT_SQ = S.OLD_EOC_CNTRT_SQ;
  

错误[42601] [IBM] [DB2] SQL0199N在“”之后使用保留字“FROM”无效。预期的令牌可能包括:“(MICROSECONDS MICROSECOND SECONDS SECOND MINUTES MINUTE”.SQLSTATE = 42601

1 个答案:

答案 0 :(得分:0)

UPDATE
(
  SELECT O.EOC_CNTRT_SQ AS old_sq
       , S.NEW_EOC_CNTRT_SQ AS new_sq
    FROM  FAMSUNIT.EOCT025_OPP_WRK O
    INNER JOIN
    (
      SELECT A.EOC_CNTRT_SQ AS OLD_EOC_CNTRT_SQ
           , (
               SELECT B.EOC_CNTRT_SQ  
                 FROM FAMSUNIT.EOCT020_CNTRT B 
                 WHERE  B.ALIAS_CNTRT_ID = A.ALIAS_CNTRT_ID 
                 AND CREA_USER_SQ IN (5,3)
             ) AS NEW_EOC_CNTRT_SQ
        FROM FAMSUNIT.EOCT020_CNTRT A       
        WHERE  A.ALIAS_CNTRT_ID IN ('12826')  
        AND CREA_USER_SQ NOT IN (5,3)
    ) S ON O.EOC_CNTRT_SQ = S.OLD_EOC_CNTRT_SQ
) foo
SET foo.old_sq = foo.new_sq
;