You can do this with two statements, for example:
Insert other
when somevalue is null
INSERT INTO othertable SELECT 1, 2, 3 FROM bigtable WHERE somevalue IS NULL;
Then left join to both tables on Somevalue
will be null
or not null
SELECT Coalesce(othertable.newlyinsertedvalue, weirdtable.someothervalue) foo, column1, column2 FROM bigtable LEFT OUTER JOIN othertable ON somevalue IS NULL LEFT OUTER JOIN weirdtable ON somevalue IS NOT NULL
I guess you really need to change the connections to be something like
LEFT OUTER JOIN othertable ON somevalue IS NULL and bigtable.id = othertable.id LEFT OUTER JOIN weirdtable ON somevalue IS NOT NULL and bigtable.id = weirdtable .id
Note. I'm not sure the equivalent of DB2 Coalesce
Conrad frix
source share