Quantcast
Channel: SQL Server Database Engine forum
Viewing all articles
Browse latest Browse all 12963

Autogenerated ID in Merge (Inserting row)

$
0
0

Hi,

I want to insert using the Merge. However, I need to have a column, much like as an "identity" column that does the increment for the sequence number automatically, without looping through for bulk insert.

I can't create an identity column field because the sequence number is not unique key. 

is there a way to create the insert without using cursor?

USING (SELECT a.col1,
 	      a.col2,
 	      a.col3,
       FROM table1 a
       LEFT JOIN table2 b ON a.col1 = b.col1
       ) as src
ON (trget.col2 = src.col2)
WHEN NOT MATCHED BY TARGET THEN
	INSERT	(col1,
                         col2,
                         col3)
        VALUES
                        (src.col1,
                         src.col2,
                         src.col3);


cherriesh


Viewing all articles
Browse latest Browse all 12963

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>