February 21, 2003 at 8:00 am
Hi,
I have a insert trigger(Trigger1) on Table1.
When I insert one record into Table1 I need to make 2 records and insert them into Table2.Table2 also has insert trigger(Trigger2).But when Trigger1 fired only one record insert into Table2, then fires Trigger2....I have a problem because I am loosing one transaction.
Thanks a lot,
Jelena
February 21, 2003 at 8:50 am
Can you post part of the trigger1 sintax?
February 21, 2003 at 9:02 am
CREATE TRIGGER .... ON [dbo].[...]
FOR INSERT
AS
DECLARE @AccTransCode varchar(10)
--triger insertuje u tabelu AccTransaction izvrsena narocila (prodaje)
DECLARE @TransactionID int
DECLARE @TransactionIDNew int
DECLARE @BuyerReference varchar(10)
DECLARE @SellerReference varchar(10)
IF UPDATE(BuyerReference) and UPDATE(SellerReference)
BEGIN
EXEC GetNextIdentity 'AccTransaction' , @TransactionID output
BEGIN
SET @SellerReference = (SELECT a.SellerReference FROM inserted AS a INNER JOIN Trade as b ON(a.TradeId = b.TradeId))
SET @BuyerReference = (SELECT a.BuyerReference FROM inserted AS a INNER JOIN Trade as b ON(a.TradeId = b.TradeId))
RAISERROR ('Vrednost SellerReference %s ', 16, 1, @SellerReference, 1, 32)
RAISERROR ('Vrednost BuyerReference %s ', 16, 1, @BuyerReference, 1, 32)
IF (@SellerReference IS NOT NULL)
BEGIN
INSERT INTO AccTransaction(TransactionID, Datum, dCredit, dDebit, nPar1, dtPar1, dPar1,dPar2, AccTransCode,TransTypeID)
SELECT @TransactionID, a.TradeTime, a.Volume, a.[Value], a.SymbolID, a.TradeTime, a.Volume, a.Price, a.SellerReference,1
FROM inserted a
EXEC GetNextIdentity 'AccTransaction' , @TransactionIDNew output
INSERT INTO AccTransaction(TransactionID, Datum, dCredit, dDebit, nPar1, dtPar1, dPar1,dPar2, AccTransCode, TransTypeID)
SELECT @TransactionIDNew, a.TradeTime, a.[Value], a.Volume, a.SymbolID, a.TradeTime, a.Volume, a.Price, a.BuyerReference,1
FROM inserted as a
--WHERE a.SellerReference <> null
END
END
....
February 21, 2003 at 9:03 am
CREATE TRIGGER .... ON [dbo].[...]
FOR INSERT
AS
DECLARE @AccTransCode varchar(10)
--triger insertuje u tabelu AccTransaction izvrsena narocila (prodaje)
DECLARE @TransactionID int
DECLARE @TransactionIDNew int
DECLARE @BuyerReference varchar(10)
DECLARE @SellerReference varchar(10)
IF UPDATE(BuyerReference) and UPDATE(SellerReference)
BEGIN
EXEC GetNextIdentity 'AccTransaction' , @TransactionID output
BEGIN
SET @SellerReference = (SELECT a.SellerReference FROM inserted AS a INNER JOIN Trade as b ON(a.TradeId = b.TradeId))
SET @BuyerReference = (SELECT a.BuyerReference FROM inserted AS a INNER JOIN Trade as b ON(a.TradeId = b.TradeId))
RAISERROR ('Vrednost SellerReference %s ', 16, 1, @SellerReference, 1, 32)
RAISERROR ('Vrednost BuyerReference %s ', 16, 1, @BuyerReference, 1, 32)
IF (@SellerReference IS NOT NULL)
BEGIN
INSERT INTO AccTransaction(TransactionID, Datum, dCredit, dDebit, nPar1, dtPar1, dPar1,dPar2, AccTransCode,TransTypeID)
SELECT @TransactionID, a.TradeTime, a.Volume, a.[Value], a.SymbolID, a.TradeTime, a.Volume, a.Price, a.SellerReference,1
FROM inserted a
EXEC GetNextIdentity 'AccTransaction' , @TransactionIDNew output
INSERT INTO AccTransaction(TransactionID, Datum, dCredit, dDebit, nPar1, dtPar1, dPar1,dPar2, AccTransCode, TransTypeID)
SELECT @TransactionIDNew, a.TradeTime, a.[Value], a.Volume, a.SymbolID, a.TradeTime, a.Volume, a.Price, a.BuyerReference,1
FROM inserted as a
--WHERE a.SellerReference <> null
END
END
....
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply