I’m writing a stored procedure. I know how to pass values from select into insert.
But, is it possible with INSERT INTO to use values and Select at the same time?
Insert into table_1 (f1, f2, f3, f4, f5, f6, f7, f8, f9,
FL1, FL2, FL3)
Select :p_f1, :v_f2, :p_f3, :p_f4,
abs(:v_f5 * :p_f5),
abs(:v_f6 * :p_f6),
:v_f7, :v_f8, :v_9 from RDB$DATABASE
UNION
Select f_lookup_id from lookup_table where (f_res >= :v_res) And (f2_lookup_id = :p_id1)
UNION
Select f_lookup_id from lookup_table where (f_res >= :v_res) And (f2_lookup_id = :p_id2)
UNION
Select f_lookup_id from lookup_table where (f_res >= :v_res) And (f2_lookup_id = :p_id3);
I guess you want to use the result set of a
SELECTstatement as a input of aINSERTstatement? Yes, that’s possible, see FB’s language reference. The part what probably causes your problem is that you don’t use theVALUESkeyword in that case, the statement would look likeOr if you want to have both "constant values" (like in
INSERT INTO ... VALUES(...)statement) and "dynamic values" (usingSELECTstatement as a source) in one statement then you can union them, i.e.where
constantsis list of values of appropriate type.UPDATE
OK, I guess what you want is actually something like