Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Migrate from Oracle trigger to MSSQL trigger Expand / Collapse
Author
Message
Posted Monday, March 10, 2014 11:38 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, March 11, 2014 2:59 AM
Points: 1, Visits: 4
Hi I am new to MSSQL server. I have problem in migration from ORACLE trigger to MSSQL server. Here below the trigger in Oracle..

<<--------Trigger Begin----------->>

create or replace
TRIGGER transactiontrigger After INSERT ON ORDERINVOICE
FOR EACH ROW
BEGIN
update A_ACCOUNT
set A_ACCOUNT.AC_RUNNING_BLC=(A_ACCOUNT.AC_RUNNING_BLC-:new.NETAMMOUNT+:new.COMMISION-:new.TDS)
where A_ACCOUNT.A_ID=:new.A_ID;
END;

<<---------Trigger END-------->>


Could you some one help me to transform the trigger in MSSQL compatible.

Nilotpalhazarika
Post #1549555
Posted Tuesday, March 11, 2014 6:20 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 6:13 AM
Points: 1,240, Visits: 9,815
There's no FOR EACH ROW syntax in SQL Server triggers. What you have instead are two tables called inserted and deleted that contain ALL rows affected by the transaction. Something along these lines should point you in the right direction, obviously you'll need to do your own verification of this:

CREATE 
TRIGGER transactiontrigger ON ORDERINVOICE
AFTER INSERT
AS
BEGIN
UPDATE A_ACCOUNT
SET A_ACCOUNT.AC_RUNNING_BLC = ( A_ACCOUNT.AC_RUNNING_BLC
- inserted.NETAMMOUNT
+ inserted.COMMISION
- inserted.TDS )
FROM A_ACCOUNT
INNER JOIN INSERTED ON A_ACCOUNT.A_ID = inserted.A_ID;
END;

Post #1549689
Posted Tuesday, March 11, 2014 6:50 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, August 5, 2014 6:10 AM
Points: 11, Visits: 64
CREATE TRIGGER transactiontrigger ON ORDERINVOICE
AFTER INSERT
AS
BEGIN
UPDATE A_ACCOUNT
SET A_ACCOUNT.AC_RUNNING_BLC=
(A_ACCOUNT.AC_RUNNING_BLC - INSERTED.NETAMMOUNT + INSERTED.COMMISION - INSERTED.TDS)
FROM A_ACCOUNT INNER JOIN INSERTED ON A_ACCOUNT.A_ID = INSERTED.A_ID

END

GO
Post #1549708
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse