Paste dest and update into the source

In SQL Server 2008, is it possible to insert data from the source table into the dest table and update the source table with the identifier @@ from the dest table at the same time?

Example

Table Source:

Id - UniqueId
Name - varchar(10) 
RealId [null] - int 

Dest table

Id - [id] INT identity
Name - varchar(10)  

I want to transfer rows from Source to Dest and update the value RealIdto @@ identity from Dest table

I can change the source in any way I like, the Dest table may not change.

What are my best options here?

Also note that the "Name" column may contain duplicates, so I cannot join this.

(Real tables are much more complicated, but this should give an idea of ​​what I want)

+5
source share

All Articles