Using db2 v 8.1.0.36 Fixpack 0 Windows XP SP2
Basically I want to run an update and using one statement I want to reuse data from a subquery.
So I have something like this currently:
update parent p
set p.field1 = case
when p.field2 = 1 and (select c.field1 from child c) = 'A'
then 'T'
when p.field2 = 2 and (select c.field1 from child c) = 'A'
then 'F'
end
This is obviously dumbed down, but the point is that I want to reuse the data from the (select c.field1 from child c) query so that I don't need to re-run it all the time and I want to be able to do it one command.
Is there a way, using updates, to do this? I know that with inserts you can use WITH VALUES for something like that, but that doesn't seem to work and I'm having difficulty finding the documentation for it - but something like how WITH VALUES works would work sufficiently. Any ideas?
Thanks,
Keith