Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Oracle-sqlserver(Trigger)

Author  Topic 

purisqlserver
Yak Posting Veteran

73 Posts

Posted - 2003-04-28 : 04:52:37
Hi,

Whts the alternative to "for each row" in oracle for sql server 2K.
This is used within the trigger(for banking transactions).
Cursor is the only way?

create or replace trigger trig_acc
after insert or update on accounts
for each row
declare
acc accounts.aid%type;
attyp accounts.atid%type;
vcusid customer.cid%type;
bal customer.opbal%type;
dat customer.opdate%type;
intid interest.irid%type;

BEGIN
acc:=:New.aid;
attyp:=:New.atid;
intid:=1;
if inserting then
vcusid:=:new.cid;
else
vcusid:=:old.cid;
end if;
select opbal into bal from customer where cid=vcusid;
select opdate into dat from customer where cid=vcusid;
IF attyp=1 THEN
insert into savings(savingsid,aid,savingsdate,savingsbal,irid)
values (sav.nextval,acc,dat,bal,intid);
ELSIF attyp=2 THEN
insert into currentac(currentid,aid,currentdate,currentbal)
values (cur.nextval,acc,dat ,bal);
END IF;
END;


Thanx.....



Andraax
Aged Yak Warrior

790 Posts

Posted - 2003-04-28 : 05:01:23
Hello!

In the trigger, you can access two logical tables: inserted and deleted. These tables contain the rows which are being inserted, deleted or updated. This allows you to manipulate the data or do integrity checks.

Look up "CREATE TRIGGER" in BOL for more information and syntax.

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-04-28 : 07:31:58
Wasn't this answered already?

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=25286

Go to Top of Page
   

- Advertisement -