Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Merge Expand / Collapse
Author
Message
Posted Monday, February 18, 2013 9:26 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum 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
Post #1421266
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse