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)
 Update Trigger with Conditional Insert Option

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-02-13 : 07:49:59
Eric writes "I am trying to setup a trigger to Create a new record in a DB when an update to a Status='Hold' and Generic='Y'.

Insert Into TableA (Quantity, Price, SellerName, Generic ) VALUES (3, 5.77, 'Johnson', 'Y')

Other Fields; Status
Status is defaulted to 'active'

The Idea is that when status is updated to 'Hold' and Generic='Y'. I want to create a new record using the values from the row that had its' status altered.

OS MS Server 2000
DB SQL 2000
Newest Service Packs installed."

Nazim
A custom title

1408 Posts

Posted - 2002-02-13 : 08:20:47
you can write a trigger on update

on this lines

begin tran
if Exist(select * from inserted where status='Hold' and Generic='Y')
insert into tablename(colunm1,column2,column3) select column1,column2,column3 from inserted

if @ERROR<> 0
begin
RAISERROR ('your error message',16,1)
rollback tran
end

commit tran


Check this Article by grath http://www.sqlteam.com/item.asp?ItemID=6494

it should help you in writing triggers
HTH

--------------------------------------------------------------
"Happiness is not something you experience, it's something you remember."

Edited by - Nazim on 02/13/2002 08:22:32
Go to Top of Page
   

- Advertisement -