我需要将条件的旧样式SQL外连接实现为新样式。
我无法转换条件的最后一行。
旧样式查询:
SELECT cpd.customer_ref, cpd.product_seq, bci.contract_inst_id,
bci.start_dat bci_start_dat, bci.end_dat bci_end_dat
FROM custproductdetails cpd, balcontractinstance bci
WHERE cpd.customer_ref = bci.customer_ref(+)
AND cpd.contract_seq = bci.contract_seq(+)
AND cpd.end_dat >= bci.start_dat(+) AND cpd.end_dat <= bci.end_dat(+);
答案 0 :(得分:0)
我假设你要从oracle语法转到sqlserver等,这需要ansi语法,不管数据库是什么,最好一般使用#Ip /
Select a.a, b.a
From a, b
Where a.a = b.a(+)
与
相同{{1}}
答案 1 :(得分:0)
我相信这可以做你想要的:
SELECT cpd.customer_ref, cpd.product_seq, bci.contract_inst_id,
bci.start_dat bci_start_dat, bci.end_dat bci_end_dat
FROM custproductdetails cpd LEFT JOIN
balcontractinstance bci
ON cpd.customer_ref = bci.customer_ref AND
cpd.contract_seq = bci.contract_seq AND
cpd.end_dat >= bci.start_dat AND
cpd.end_dat <= bci.end_dat;
一般规则是,(+)
引用的表会添加其他行。这使它成为LEFT JOIN
中的第二个表。
答案 2 :(得分:0)
旧样式查询:
SELECT cpd.customer_ref, cpd.product_seq, bci.contract_inst_id,
bci.start_dat bci_start_dat, bci.end_dat bci_end_dat
FROM custproductdetails cpd, balcontractinstance bci
WHERE cpd.customer_ref = bci.customer_ref(+)
AND cpd.contract_seq = bci.contract_seq(+)
AND cpd.end_dat >= bci.start_dat(+)
AND cpd.end_dat <= bci.end_dat(+);
'新'样式查询:
SELECT cpd.customer_ref, cpd.product_seq, bci.contract_inst_id,
bci.start_dat bci_start_dat, bci.end_dat bci_end_dat
FROM custproductdetails cpd LEFT JOIN balcontractinstance bci
ON cpd.customer_ref = bci.customer_ref
AND cpd.contract_seq = bci.contract_seq
AND cpd.end_dat >= bci.start_dat
AND cpd.end_dat <= bci.end_dat;
你可以看到它非常相似。