sql server - Split table and insert with identity link -


I have 3 tables similar to the structure below

  create table [dbo] [EmpBasic] ([EmpID] [int] identification (1,1) No zero primary key, [name] [varchar] (50), [address] [varchar] (50)) Create table [dbo]. [EmpProject] [[DBO]] [[DBO]] [[DBO]] with [[mpid] [int] tap primary key, epipisy [[API6] [varchare] (50)). [Mpful_mmpi] ([object] [Intid] [Intid] identified (1,1) NOT NULL PRIMARY KEY, [T1Name] [varchar] (50), [T1Address] [varchar] (50), [T1EmpProject] [varchar] (50))  

The EmpFull_Temp table is a record with a dummy object ID column ... I want to populate the first 2 tables with the records in this table ... but the first 2 With EmpID as a reference between tables.

A stored procedure ...

  table # Aidiss (Mpid Biltint, Ojjid Binit) into EmpBasic output Inserted.EmpID, T1Name in EmpFull_Temp.ObjectID #IDSS, Select EmpFull_Temp from T1Address where ObjectID & lt; As 106 select select A.EmpID in EmpProject, A. BIT 1EmpProject #IDSS, EmpFull_Temp as B where A.ObjID = B.ObjectID  

But it says. The multi-part identifier "EmpFull_Temp.ObjectID" can not be constrained.

Can you please help me find it ...

Edit: There is no guarantee that [name] + [ Address] [EmpBasic] table

Your EmpProject will be unique in the table, you may only EmpID column

 DECLARE @Count int declaration @NextEmpID int decalar @StartObjectID int decryge not want the primary key constraint for the primary category ID on @EndObjectID transfer (inclusive) SET @StartObjectID = 1 SET @EndObjectID = 105 BEGIN TRAN - Lock Ebl so IDENT_CURRENT valid SELECT @Count = COUNT (*) FROM [EmpBasic] from (TABLOCKX, HOLDLOCK) SELECT @Count = COUNT (*) (TABL OCKX, HOLDLOCK) with [EmpProject] SELECT @NextEmpID = IDENT_CURRENT ( ' EmpBasic ') SET IDENTITY_INSERT [EmpBasic] INSERT [EmpBasic] on [EmpID], [name], [select address]) in @NextEmpID + ROW_NUMBER () over (order by object), [TlName], [TlAddress] fROM [ EmpFull_Temp] WHERE [object] of @ Stast object ID and @EndObjectID SET IDENTITY_INSERT [EmpBasic] OFF INSERT [EmpProject] ([EmpID], [EmpProject]) select @NextEmpID + ROW_NUMBER (between) over (ORDER BY ObjectID), [T1EmpProject] FROM [EmpFull_Temp] WHERE [object] between @ Start object ID and @EndObjectID COMMIT TRAN 

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -