SQL2K database
I am having some difficulty with an existing trigger. I performs quite a few calculations and needs data from other tables to do so, but it only updates the one table it is attached to. It's been fine for a few years but they recently asked me to pull in one more piece of data which would have to come from a third table. The code below is the first section - i trimmed out the middle part of the declarations and first select as we're talking about 400 variables:
A is a field that exist as the same name in all tables and is the uid for the records.
IF EXISTS
(SELECT *
FROM SYSOBJECTS
WHERE ID = OBJECT_ID(N'[dbo].[Calculations]') AND OBJECTPROPERTY(ID, N'IsTrigger') = 1
)
DROP TRIGGER [dbo].[Calculations]
GO
-- 30a DEV 090918
CREATE TRIGGER [Calculations]
ON [CALLLOG]
--WITH ENCRYPTION
FOR INSERT, UPDATE
AS
SET NOCOUNT ON
DECLARE @A VARCHAR(8), @E VARCHAR(25),
@B INT, @F INT,
@C INT, @G INT,
@D INT, @H INT
-------------------------------------------------------------------------------------------------------------------------------
--Get the values for the fields
SET ROWCOUNT 1
SELECT @A = [AA], @E = [EE],
@B = [BB], @F = [FF],
@C = [CC], @G = [GG]
FROM [INSERTED]
SET ROWCOUNT 500
SET ROWCOUNT 1
SELECT
@D = [DD]
FROM SUBSET
WHERE A = @AA
-- recently added select causes trigger to not fire
SET ROWCOUNT 1
SELECT
@H = [HH]
FROM DETAIL
WHERE A = @AA
The problem started after I added this last select section. Now the trigger does not fire. If i comment out those five last lines, it works fine.
I inherited this code form someone else and we're replacing the system in a few months, so there isn't time or resources to rewite anything.
What am I doing wrong to add a table here? I appreciate the help.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TheWkndr
I am having some difficulty with an existing trigger. I performs quite a few calculations and needs data from other tables to do so, but it only updates the one table it is attached to. It's been fine for a few years but they recently asked me to pull in one more piece of data which would have to come from a third table. The code below is the first section - i trimmed out the middle part of the declarations and first select as we're talking about 400 variables:
A is a field that exist as the same name in all tables and is the uid for the records.
IF EXISTS
(SELECT *
FROM SYSOBJECTS
WHERE ID = OBJECT_ID(N'[dbo].[Calculations]') AND OBJECTPROPERTY(ID, N'IsTrigger') = 1
)
DROP TRIGGER [dbo].[Calculations]
GO
-- 30a DEV 090918
CREATE TRIGGER [Calculations]
ON [CALLLOG]
--WITH ENCRYPTION
FOR INSERT, UPDATE
AS
SET NOCOUNT ON
DECLARE @A VARCHAR(8), @E VARCHAR(25),
@B INT, @F INT,
@C INT, @G INT,
@D INT, @H INT
-------------------------------------------------------------------------------------------------------------------------------
--Get the values for the fields
SET ROWCOUNT 1
SELECT @A = [AA], @E = [EE],
@B = [BB], @F = [FF],
@C = [CC], @G = [GG]
FROM [INSERTED]
SET ROWCOUNT 500
SET ROWCOUNT 1
SELECT
@D = [DD]
FROM SUBSET
WHERE A = @AA
-- recently added select causes trigger to not fire
SET ROWCOUNT 1
SELECT
@H = [HH]
FROM DETAIL
WHERE A = @AA
The problem started after I added this last select section. Now the trigger does not fire. If i comment out those five last lines, it works fine.
I inherited this code form someone else and we're replacing the system in a few months, so there isn't time or resources to rewite anything.
What am I doing wrong to add a table here? I appreciate the help.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TheWkndr