Insert consecutive numbers

Posted by Markus on Stack Overflow See other posts from Stack Overflow or by Markus
Published on 2010-05-26T18:08:19Z Indexed on 2010/05/26 18:11 UTC
Read the original article Hit count: 192

Filed under:

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;

© Stack Overflow or respective owner

Related posts about tsql