DELETE FROM ABC
WHERE EXISTS(
SELECT policy_no, certificate_no, renl_cert_no, eff_dt_seq_no,
(CASE WHEN source_system_id='AP' THEN 'NA' ELSE source_system_id END )
FROM I_ABC
WHERE ABC.policy_no = I_ABC.policy_no
AND ABC.certificate_no = I_ABC.certificate_no
AND ABC.renl_cert_no = I_ABC.renl_cert_no
AND ABC.eff_dt_seq_no = I_ABC.eff_dt_seq_no
AND ABC.source_system_id = ????? );
如何将?????
填入我从上面的select语句中检索的最后一列(以粗体突出显示)。我正在使用sql server。
答案 0 :(得分:0)
由于您只是使用EXISTS
检查记录,因此您只需将该语句移至WHERE
子句:
delete from ABC
where exists(
select NULL
from I_ABC
where
ABC.policy_no=I_ABC.policy_no
and ABC.certificate_no=I_ABC.certificate_no
and ABC.renl_cert_no=I_ABC.renl_cert_no
and ABC.eff_dt_seq_no=I_ABC.eff_dt_seq_no
and (case when ABC.source_system_id='AP' then 'NA' else ABC.source_system_id end) =
(case when I_ABC.source_system_id='AP' then 'NA' else I_ABC.source_system_id end )
);