I was asked if you could have an insert statement, which had an ID field that was an “identity” column, and if the value that was assigned could also be inserted into another field in the same record, in the same insert statement.
Is this possible (SQL Server 2008r2)?
Thanks.
You cannot really do this – because the actual value that will be used for the
IDENTITYcolumn really only is fixed and set when theINSERThas completed.You could however use e.g. a trigger
This would fire right after any rows have been inserted, and would set the
OtherIDcolumn to the values of theIDENTITYcolumns for the inserted rows. But it’s strictly speaking not within the same statement – it’s just after your original statement.