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 Trigger.... Please help...

Author  Topic 

samvirgie
Starting Member

1 Post

Posted - 2002-11-04 : 05:46:34
I have two tables below named stock and sent in a trouble to make trigger. What I need, If any user update or insert data in stock table,the "sent" column should change to '1' and also insert that updated row to stocksent table. We have to sonsider the duplicate value should not be added to stocksent table..
After senting Stocksent data to Another Location I want to delete the records in stocksent table and to change the sent column of the stock table to '0' again..

Please any one can help me....?

create table STOCK,stocksent
(itemcod char(8)primary key,
refcode char(10),
grpid char(5),
grpdrs char(6),
brandname char(15),
descript char(30),
pack char(15),
stock numeric(5),
sent int(1)default'0',
)


M.E.
Aged Yak Warrior

539 Posts

Posted - 2002-11-04 : 11:34:26
create trigger blahblahtrigger
for insert,update
as
update stock set sent = 1 where itemcod = (select itemcod from inserted)
insert into stock (list columns here, I'm too lazy)
select list columns here, once again to lazy
from inserted

This will only work for single updates and inserts (you don't insert multiple lines into stock at once). If you have more then one line getting inserted and once I think changing the update statment to read

update stock set sent = 1 where itemcod in (select itemcod from inserted)

Should work, but I'm not quite sure. I think this is the answer you want, but I'm not sure if I fully understood your question/problem correctly. Post something if I've missed what your trying to do

-----------------------
SQL isn't just a hobby, It's an addiction
Go to Top of Page
   

- Advertisement -