5

我正在尝试从源表更新临时表:

    UPDATE #DETAIL
        SET EXCD_ID, CDOR_OR_AMT, CDOR_OR_VALUE
        (SELECT 
            CDID_ADDL_DATA_1, CDID_ADDL_DATA, CDID_VALUE_STRING
        FROM
            CMC_CDID_DATA CDID
        WHERE
            CDID.CLCL_ID = DTL.CLCL_ID AND
            CDID.CDML_SEQ_NO = DTL.CDML_SEQ_NO AND
            CDID_TYPE = 'NDC'
    )
    FROM #DETAIL DTL
    WHERE DTL.CDOR_OR_ID = 'XS'

不幸的是它抱怨

Incorrect syntax near ',' (on the '(SELECT' line)
Incorrect syntax near 'FROM' (the second one)
4

3 回答 3

4

经过多次试验和错误,我在工作中获得了一些帮助,我们想出了这个:

    UPDATE #DETAIL
        SET DTL.EXCD_ID = CDID.CDID_ADDL_DATA_1,
            DTL.CDOR_OR_AMT = CONVERT(MONEY,CDID.CDID_ADDL_DATA),
            DTL.CDOR_OR_VALUE = CDID.CDID_VALUE_STRING
    FROM #DETAIL DTL
    INNER JOIN 
            CMC_CDID_DATA  CDID ON
            CDID.CLCL_ID = DTL.CLCL_ID AND
            CDID.CDML_SEQ_NO = DTL.CDML_SEQ_NO 
    WHERE DTL.CDOR_OR_ID = 'XS'
          AND CDID.CDID_TYPE = 'NDC'

sybase 好像接受哪个。

于 2012-05-04T18:10:05.363 回答
3

您必须像这样进行更新:

UPDATE #DETAIL
SET DTL.EXCD_ID = CDID.CDID_ADDL_DATA_1,
    DTL.CDOR_OR_AMT = CDID.CDID_ADDL_DATA
    DTL.CDOR_OR_VALUE = CDID.CDID_VALUE_STRING
FROM #DETAIL DTL
INNER JOIN (SELECT 
            CDID_ADDL_DATA_1, CDID_ADDL_DATA, CDID_VALUE_STRING
        FROM
            CMC_CDID_DATA ) CDID ON CDID.CLCL_ID = DTL.CLCL_ID AND
            CDID.CDML_SEQ_NO = DTL.CDML_SEQ_NO AND
            CDID_TYPE = 'NDC'
WHERE DTL.CDOR_OR_ID = 'XS'

查看这篇文章了解更多信息!

于 2012-05-04T09:08:39.203 回答
0

我刚刚尝试过,它有效(在 Oracle 上)

update dstTable T
    set (T.field1, T.field2, T.field3) = 
           (select S.value1, S.value2, S.value3
            from srcTable S
             where S.key = T.Key);

不幸的是,这是 Oracle 特定的语法。

警告:请注意,上面的更新没有 where 子句。它更新整个表。如果子查询不返回任何行,则目标字段设置为 NULL。此外,如果子查询返回多于一行,也是错误的。

于 2022-02-10T01:27:54.570 回答