This should (hopefully) be a fast one, unfortunately I am a little bit slow today and need your help.
I've basically wrote an INSERT statement with the following structure in order to insert multiple rows with a single statement:
INSERT INTO TABLE_TO_INSERT_INTO
SELECT
-- ...,
-- ...,
-- ...,
(SELECT MAX(ID)+1 FROM SOME_TABLE) As ID,
-- ...,
-- ...,
FROM
(
-- Subqueries and Joins here
-- ...
) ;
This generally works perfectly fine, but for one part: the ID.
It has got to be unique (a constraint makes sure of that), but with the current way of selecting the ID that is not the case, as it uses the selected value for all rows that are inserted via the above statement.
Is there any way of forcing a reevalution of the (SELECT MAX(ID)+1 FROM SOME_TABLE) As ID
part after every row inserted?
I don't really want to use a trigger, but instead implement it on a pure SQL basis.
I hope someone has a solution, I am at a loss today and can't really see it. Thanks in advance!