troubleshooting Question

SQL Trigger | Inserting multiple entries

Avatar of Muhammad Burhan
Muhammad BurhanFlag for Pakistan asked on
Microsoft SQL Server
25 Comments2 Solutions123 ViewsLast Modified:
We have two Databases, Source -> 'HR_TimeOffice' and Dest -> 'HR'.
we have to create a trigger which just replicate new entries automatically from sources DB's table to destination DB's table.

INSERT INTO [HR].[dbo].[EmpAttendance] 
SELECT     RIGHT(REPLICATE(0,5)+[HR_TimeOffice].DBO.EmpAttendance.EmpCode ,5) EMPLOYEENO,
           CONVERT(CHAR(8), i.DateTime, 112),i.DateTime,
           case when (i.InOut='I') then 'IN' else 'OUT' End,'0',null
           FROM inserted i
           	 INNER JOIN [HR_TimeOffice].dbo.EmpAttendance ON
	     EmpAttendance.EmpCode  = i.EmpCode

the trigger did its job as it should, but it insert multiple entries with same data in destination table; *review attachments.
Also please advice if we want to replicate those entries in the database which is hosted by another server 'Server2' with same DB name 'HR' and same tables. Can we use 'Linked Server' feature to do this ?
both server are in the same domain as well.
Senior Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 25 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 25 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros