I'm usually pretty good with these UPDATE stmts, however, this one is boggling me:
Background: I need to update a column with a value that I get from using a WITH stmt
WITH stmt:
Code:
with temp as (
select rbt.wid_clm as old_wid,
clm.id_clm
from f_clm_rbt_sts rbt
inner join d_clm clm
on rbt.wid_clm = clm.wid_clm
where rbt.wid_sc_clm = 4
)
select max(clm.wid_clm) as new_wid,
temp.old_wid
from d_clm clm
inner join temp
on temp.id_clm = clm.id_clm
group by temp.old_wid)
My assumed UPDATE stmt:
Code:
update f_clm_rbt_sts rbt
set rbt.wid_clm = (select t1.new_wid
from (with temp as (
select rbt.wid_clm as old_wid,
clm.id_clm
from f_clm_rbt_sts rbt
inner join d_clm clm
on rbt.wid_clm = clm.wid_clm
where rbt.wid_sc_clm = 4
)
select max(clm.wid_clm) as new_wid,
temp.old_wid
from d_clm clm
inner join temp
on temp.id_clm = clm.id_clm
group by temp.old_wid
) t1
where rbt.wid_clm = t1.old_wid
)
Can I use WITH stmts within UPDATE stmts?