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)
 Trigger to handle multiple rows

Author  Topic 

e.bar
Starting Member

25 Posts

Posted - 2006-03-08 : 16:46:08
I´m new to triggers and find needing to create one, make sure it can handle multiple rows in the trigger table. The code that fires only one row:


CREATE TRIGGER InsPeriods ON dbo.table2
FOR INSERT
AS
declare
@indice int,
@itemID int,
@periods int,
@payment_date datetime,
@period_value decimal(15,2)
select @periods=periods, @period_value=total/periods, @paymentdate=startpayment, @itemID=itemID from inserted
set @indice = 1
while @indice <= @periods
begin
insert dbo.table3 (itemID, installment, periodvalue, paymentdate)
values (@itemID, @indice, @paymentvalue, DATEADD(month,@indice-(1),@paymentdate))
set @indice= @indice+1
end

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-03-08 : 17:11:09
Duplicate of another thread:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=62931

Please do not post the same question on a new thread.


CODO ERGO SUM
Go to Top of Page
   

- Advertisement -