Loop with SCOPE_IDENTITY()

Scott Baldridge
Scott Baldridge used Ask the Experts™
on
Hello, I need to loop through table a and insert into table b get the SCOPE_IDENTITY() and use that to insert more data from table a into table c using the SCOPE_IDENTITY() .

table a is a flat table with company and worker information.
table b will become company table
table c will become worker table using company.Id(SCOPE_IDENTITY() ) as worker.companyId.

What is the best way to do this type of statement?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
IT Engineer
Distinguished Expert 2017
Commented:
I need to loop through table
For looping through a table use CURSOR.

insert into table b get the SCOPE_IDENTITY() and use that to insert more data from table a into table c using the SCOPE_IDENTITY() .
If you use an Insert trigger solution you shouldn't need to use SCOPE_IDENTITY().

This is as generic answer for a generic question.
If you want a more detailed answer please provide more details for your question.
Vitor MontalvãoIT Engineer
Distinguished Expert 2017

Commented:
Only possible answer for the question.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial