insert in master child table without cursors
Posted on 2011-10-13
I have a select query.
and, need to insert results from the select query above into 2 tables that have a
master child relationship. Is there a way to do this without cursors such that once
I insert in master table I can insert in child table and use the primary key in master table to into the
fk in the child table. please note the primary key in the master table is an identity column.
select col1, col2, col3
stmt 1) insert col1 in master table
stmt 2) insert col2, col3 in child table
use primary key generated in stmt 1 to be used in fk in stmt 2.
if 10 records are generated in select stmt then 10 records go into master table and 10 go into
child table so 1-1 relationship between master child tables.