我尝试在DB2中使用2个select语句执行SP。如果第一个select返回null,则执行第二个select。比如说
Select a, b, c from table A where...
--如果第一次选择返回null
Select a, from table B where...
我试了很多办法,但没有一个奏效。谢谢
e37o9pze1#
您可以使用此通用模式,当然您必须调整两个结果集以使其匹配
WITH first AS ( SELECT ..result1.. FROM table1 WHERE ..clause1.. ) SELECT ..result1.. FROM first UNION SELECT ..result2.. FROM table2 WHERE 0=(SELECT COUNT(1) FROM first) AND ..clause2..
7vhp5slm2#
下面是一个简单的写法
Select a, from table B where... and not exists (select * from table a where...) union select a,.. from table A)
2条答案
按热度按时间e37o9pze1#
您可以使用此通用模式,当然您必须调整两个结果集以使其匹配
7vhp5slm2#
下面是一个简单的写法