UPDATE a SET a.refund_status = b.dealstat , a.refund_time = b.dealtime FROM dwi_store_setmt_ord_dtl_p a INNER JOIN sdi_dgmps_dgmpsdb_mstore.chainstorefeemangdtl_p b ON a.comp_code = trim(upper(b.companycode)) AND a.src_pid = trim(b.pid) WHERE a.refund_status = 0 AND ISNULL(a.refund_time,'') = '' AND b.dealstat = 1 AND ISNULL(a.dealtime,'') <> '' ;改为用merge into 更新
时间: 2024-03-20 12:44:27 浏览: 67
Sure, here's the equivalent MERGE statement:
```
MERGE INTO dwi_store_setmt_ord_dtl_p AS a
USING (
SELECT trim(upper(b.companycode)) AS comp_code,
trim(b.pid) AS src_pid,
b.dealstat,
b.dealtime
FROM sdi_dgmps_dgmpsdb_mstore.chainstorefeemangdtl_p AS b
WHERE b.dealstat = 1
) AS b
ON a.comp_code = b.comp_code
AND a.src_pid = b.src_pid
AND a.refund_status = 0
AND ISNULL(a.refund_time, '') = ''
AND ISNULL(a.dealtime, '') <> ''
WHEN MATCHED THEN
UPDATE SET a.refund_status = b.dealstat,
a.refund_time = b.dealtime;
```
This MERGE statement combines the source table `sdi_dgmps_dgmpsdb_mstore.chainstorefeemangdtl_p` with the target table `dwi_store_setmt_ord_dtl_p` based on the matching conditions specified in the ON clause. When a match is found, the specified columns in the target table are updated with the corresponding values from the source table.
阅读全文