Hello -
I created a Store Procedure to have Table A sync with Table B by doing an insert of the data that it does not have.
The issue I'm running into is when I run the Stored Proc it's taking longer then just running the Insert itself. I want to put this into a Job to run at night but also to have it in a Transaction in case I need to rollback as well on an error. Can someone take a look to see if I have to much or not enough in my script?
USE [Dev_SageReporting]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[hgsp_backloglaborb_sync]
AS
DECLARE @intErrorCode INT
BEGIN TRAN
INSERT INTO BackLogLaborB
SELECT *
FROM BackLogLaborCurrent AS A
WHERE NOT EXISTS ( SELECT *
FROM BackLogLaborB AS B
WHERE A.PIT = B.PIT )
SET NOCOUNT ON;
SELECT @intErrorCode = @@ERROR
IF ( @intErrorCode <> 0 )
ROLLBACK TRANSACTION
ELSE
COMMIT TRANSACTION