I am insert data into a table called Persons using the code below. Basically i am moving data out of the Operations table into the Persons table.
insert into Persons ( Gender, Lan, Country, Status )
(select id from vw_Counties where cast( code as int ) = cast(ope_DistrCode as int )) countyid,
1, 1 from [Operations]
where pat_id is null and (ope_distrCode is not null or kon is not null)
The Persons table has an identity column called id.
What i would like to do is create a foreign key reference from Operation to Persons.
I have a column in the Operations table called Pat_id and i want to set it to the Id value of the newly created row in Persons.
I wonder if this can be done with an OUTPUT clause, or a Merge statement?