SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Migrate from Oracle trigger to MSSQL trigger


Migrate from Oracle trigger to MSSQL trigger

Author
Message
myofficenilu
myofficenilu
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
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
HowardW
HowardW
SSCertifiable
SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)

Group: General Forum Members
Points: 6223 Visits: 9892
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;


gautham.gn
gautham.gn
SSC-Enthusiastic
SSC-Enthusiastic (110 reputation)SSC-Enthusiastic (110 reputation)SSC-Enthusiastic (110 reputation)SSC-Enthusiastic (110 reputation)SSC-Enthusiastic (110 reputation)SSC-Enthusiastic (110 reputation)SSC-Enthusiastic (110 reputation)SSC-Enthusiastic (110 reputation)

Group: General Forum Members
Points: 110 Visits: 86
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search