Insert consecutive numbers
- by Markus
Hi. I have a table A (Acons, A1, A2, A3) in which I should insert information from another table B with columns (B1, B2, B3). The Acons is a column in which should contain some consecutive numbers (it is not an identity and I cannot make it identity). I know xmin - starting the from number the sequence has to be computed. How can I insert the rows into the table A, using a single Insert statement?
I tried like the following, but it didn't work:
DECLARE @i AS INT;
SET @i = xmin;
INSERT INTO A(Acons, A1, A2, A3)
SELECT @i = (Bcons = (@i + 1)), B1, B2, B3
FROM B
Unfortunatelly, the above solution does not work;