|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Monday, February 18, 2013 11:09 PM
Points: 1,
Visits: 2
|
|
Hi,
If two users are performing same operation then the below stored procedure provides the output based on single context(combination of first/second users result) or separate context execution,
Source table: Create table StagingTable (personName varchar(50)) insert into StaginTable values('Test1') .. .. .. insert into StaginTable values('Test10,000')
Target table: Create table TargetTable (personId int identity(1,1), personName varchar(50)) insert into TargetTable values('Already1') .. .. insert into TargetTable values('Already10')
Now I am having 10 records in TargetTable with 10 records with personId (1 to 10), so my question is to insert 10,000 records from StagingTable to TargetTable & make it as 10,010 records meantime I need only 10,000 unique identity values by excluding 10 identity values with the help of merge concept in sql server 2012.
Create procedure Merge_GetNewIdentityValues As MERGE TargetTable AS T USING StagingTable AS S ON 1 != 1 when not matched then insert(personName) values(S.StagingTable) output inserted.personId; -- Get the identity field values [newly inserted one]
Thanks, S.Venkatesh
|
|
|
|