I have following statement with which I would like to update table based on some of its columns entry. I use Firebird 2.1 and documentation shows that update can be used with CTEs but my flamerobin stubbornly insists that update statement is not recognized. Can you shed some light on that?
with cte as (select gen_id(gen_new,1) as num , N.elm_prof, N.elm_mat From
(select distinct elm_mat, elm_prof from elements ) N )
update elements E set E.PROP_TYPE = cte.num where cte.elm_prof = E.ELM_PROF and cte.elm_mat = E.ELM_MAT
Engine Message :
Dynamic SQL Error
SQL error code = -104
Token unknown - line 3, column 1
update
merge into elements E1
using (with CTE as (select distinct e2.ELM_MAT mat1, e2.ELM_PROF mat2 from elements e2)
select gen_id(gen_new,1) num, mat1, mat2 from cte)
on E1.elm_mat = mat1 and e1.elm_prof = mat2
when matched then update set e1.prop_type = num