As far as I know, you cannot do this with direct SQL in the same script. But you can create an INSERT trigger. Now, I hate triggers, but this is one way to do this.
Depending on what you are trying to do, you can first insert rows into the temp or table, and handle the result set this way. We hope that there is a unique column that you can reference.
You can also lock the table, get the maximum key, insert your rows, and then get your maximum key again and make a range.
Trigger:
Temp table:
insert field1, unique_col into
Key Range:
Declare @minkey as int, @maxkey as int BEGIN TRANS --You have to lock the table for this to work --key is the name of your identity column SELECT @minkey = MAX(key) FROM tbl_xyz insert into tbl_xyz select field1 from tbl_abc SELECT @maxkey = MAX(key) FROM tbl_xyz COMMIT Trans SELECT * FROM tbl_xyz WHERE key BETWEEN @minkey and @maxkey
source share