以下SQL GIVES -811或JOB GET CANCELED
UPDATE RATES A
SET A.D_PROC_RATE_END = '1234'
WHERE EXISTS
(
SELECT A.C_PROCEDURE,
A.C_SPECIALTY,
A.C_PROV_TYPE,
A.C_PROCEDURE_MOD,
A.N_PROC_RATE
FROM PROC B
LEFT OUTER JOIN RATES A
ON
A.C_SPECIALTY = '181'
AND A.C_PROV_TYPE = B.C_PROV_TYPE
AND A.C_PROCEDURE = B.C_PROCEDURE
AND (A.C_PROCEDURE_MOD = B.C_PROCEDURE_MOD
OR A.C_PROCEDURE_MOD IS NULL)
AND (A.D_PROC_RATE_END IS NULL
OR A.D_PROC_RATE_END = '12/31/9999')
AND A.N_PROC_RATE = B.N_PROC_RATE
ORDER BY A.C_PROCEDURE)
这个sql不会更新每条记录以下标准吗?
答案 0 :(得分:0)
我们无法回答它是否会更新每一行。我们不知道这些数据。如果EXISTS()谓词返回' true'每次都是值,然后它会更新每一行;否则就不会。
首先运行此查询:
SELECT A.C_PROCEDURE,
A.C_SPECIALTY,
A.C_PROV_TYPE,
A.C_PROCEDURE_MOD,
A.N_PROC_RATE
FROM RATES A
WHERE EXISTS
(
SELECT A.C_PROCEDURE,
A.C_SPECIALTY,
A.C_PROV_TYPE,
A.C_PROCEDURE_MOD,
A.N_PROC_RATE
FROM PROC B
LEFT OUTER JOIN RATES A
ON
A.C_SPECIALTY = '181'
AND A.C_PROV_TYPE = B.C_PROV_TYPE
AND A.C_PROCEDURE = B.C_PROCEDURE
AND (A.C_PROCEDURE_MOD = B.C_PROCEDURE_MOD
OR A.C_PROCEDURE_MOD IS NULL)
AND (A.D_PROC_RATE_END IS NULL
OR A.D_PROC_RATE_END = '12/31/9999')
AND A.N_PROC_RATE = B.N_PROC_RATE
ORDER BY A.C_PROCEDURE)
返回的每一行都是一个要更新的行。 (在执行任何非平凡的更新之前,我几乎总是运行测试SELECT。)
您可以在将其更改为WHERE
NOT EXISTS
之后运行测试SELECT查询,以查看哪些不会更新。