Hi,
I have create Trigger on table to update another table on different server. The Trigger sends parameters to stored procedure hoping to make this process run faster but I keep getting Timeout error now. I know the trigger works find but when parameters get sent to store procedure if were the problem is, I think my production table is way to big for this to update in timely manner. Both are linked servers. So I am asking how to make this run smoother without timeout happening, if I have to change something all do it not problem because I know something has to change here and in store procedure if I remove the update statement everything works fine.
Below are my Tigger and SP.....
TRIGGER--
CREATE TRIGGER UpdateBrandID ON [dbo].[Pnr]
AFTER INSERT, UPDATE
AS
SET XACT_ABORT ON
DECLARE @ResID char(100)
DECLARE @CST varchar(100)
DECLARE @Status varchar(20)
IF (UPDATE(ReservationID))
BEGIN
Set @ResID = (Select ReservationID FROM INSERTED)
Set @CST = (Select ClientSubTrack From INSERTED)
Set @Status = (Select Status From INSERTED)
EXEC sp_UpdateBrandID @ResID, @CST, @Status
END
STORE PROCEDURE--
CREATE PROCEDURE sp_UpdateBrandID
(@ResID varchar(100),
@CST varchar(100),
@Booked varchar(20)
)
AS
Set nocount on
Declare @Brand varchar(100)
Declare @Route varchar(100)
Declare @ResFullID varchar(100)
Declare @Username varchar(100)
Declare @UserID varchar(100)
Begin
If (@Booked = 'Booked' AND @CST IS NOT NULL AND @ResID IS NOT NULL)
Begin
Set @Brand = (Select substring(@CST, patindex('%brand!%', @CST)+6, patindex('%route!%', @CST)-10))
Set @Route = (Select substring(@CST, patindex('%route!%', @CST)+6, patindex('%)', @CST)-17))
Set @ResFullID = (Select substring(@ResID, patindex('%travelworm_%', @ResID) + 11, patindex('%no%', @ResID)-12))
Set @Username = (Select UserName From Production.Reservation.dbo.tblRoute Where Route = @Route)
Set @UserID = (Select UserID From Production.Reservation.dbo.tblRoute Where Route = @Route)
UPDATE Production.Res.dbo.Reservations SET
BrandID = RTRIM(@Brand),
UserName1 = RTRIM(@Username),
UserID1 = RTRIM(@UserID)
WHERE ReservationID = RTRIM(@ResFullID)
End
If (@Booked = 'Booked' OR @Booked = 'add_to' AND @CST IS NULL)
Begin
Set @ResFullID = (Select substring(@ResID, patindex('%travelworm_%', @ResID) + 11, patindex('%no%', @ResID)-12))
UPDATE Production.Res.dbo.Reservations SET
BrandID = 1
WHERE ReservationID = RTRIM(@ResFullID)
End
End
GO
I have create Trigger on table to update another table on different server. The Trigger sends parameters to stored procedure hoping to make this process run faster but I keep getting Timeout error now. I know the trigger works find but when parameters get sent to store procedure if were the problem is, I think my production table is way to big for this to update in timely manner. Both are linked servers. So I am asking how to make this run smoother without timeout happening, if I have to change something all do it not problem because I know something has to change here and in store procedure if I remove the update statement everything works fine.
Below are my Tigger and SP.....
TRIGGER--
CREATE TRIGGER UpdateBrandID ON [dbo].[Pnr]
AFTER INSERT, UPDATE
AS
SET XACT_ABORT ON
DECLARE @ResID char(100)
DECLARE @CST varchar(100)
DECLARE @Status varchar(20)
IF (UPDATE(ReservationID))
BEGIN
Set @ResID = (Select ReservationID FROM INSERTED)
Set @CST = (Select ClientSubTrack From INSERTED)
Set @Status = (Select Status From INSERTED)
EXEC sp_UpdateBrandID @ResID, @CST, @Status
END
STORE PROCEDURE--
CREATE PROCEDURE sp_UpdateBrandID
(@ResID varchar(100),
@CST varchar(100),
@Booked varchar(20)
)
AS
Set nocount on
Declare @Brand varchar(100)
Declare @Route varchar(100)
Declare @ResFullID varchar(100)
Declare @Username varchar(100)
Declare @UserID varchar(100)
Begin
If (@Booked = 'Booked' AND @CST IS NOT NULL AND @ResID IS NOT NULL)
Begin
Set @Brand = (Select substring(@CST, patindex('%brand!%', @CST)+6, patindex('%route!%', @CST)-10))
Set @Route = (Select substring(@CST, patindex('%route!%', @CST)+6, patindex('%)', @CST)-17))
Set @ResFullID = (Select substring(@ResID, patindex('%travelworm_%', @ResID) + 11, patindex('%no%', @ResID)-12))
Set @Username = (Select UserName From Production.Reservation.dbo.tblRoute Where Route = @Route)
Set @UserID = (Select UserID From Production.Reservation.dbo.tblRoute Where Route = @Route)
UPDATE Production.Res.dbo.Reservations SET
BrandID = RTRIM(@Brand),
UserName1 = RTRIM(@Username),
UserID1 = RTRIM(@UserID)
WHERE ReservationID = RTRIM(@ResFullID)
End
If (@Booked = 'Booked' OR @Booked = 'add_to' AND @CST IS NULL)
Begin
Set @ResFullID = (Select substring(@ResID, patindex('%travelworm_%', @ResID) + 11, patindex('%no%', @ResID)-12))
UPDATE Production.Res.dbo.Reservations SET
BrandID = 1
WHERE ReservationID = RTRIM(@ResFullID)
End
End
GO