I have this procedure which is inserting records from one table to another. the destination table is having an identity column called LeadId
Create Procedure prcInsertPrd
As
Begin
Begin Transaction
Declare @Identity int
Insert into Temp_ProductsArchive (column1,column2,column3) select
(column1,column2,column3)
from Temp_Products
if(@@Error=0)
Begin
Commit
End
else
Begin
Rollback
End
End
Then I have written an Insert Trigger which will take LeadId from inserted table and Insert it to another table with other values as-
Alter TRIGGER trgInsertTopProducts
ON Temp_ProductsArchive
AFTER INSERT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
declare @LeadId as int
Select @LeadId=LeadId from inserted
print @LeadId
Insert into Temp_ProductsTop(column4,LeadID,Column5,column6) Select column4,@LeadID 'LeadID',column 5,column6 from Temp_Products
END
GO
The problem is I am getting the First generated LeadiD not all the LeadIds. The LeadiD column in Temp_ProductsTop table is having only this value repeated for the number of records