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 2005 Forums
 Transact-SQL (2005)
 trigger help

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2009-08-06 : 13:39:01
how can I code in the trigger that it should insert into another table the identity field of the table that i'm making the trigger on


CREATE TRIGGER insertinfo ON [dbo].[order_details]
FOR INSERT
AS
insert into information(order_item_id,mfg_status) values(@@identiry,'nothing')"

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-08-06 : 13:46:42
CREATE TRIGGER insertinfo ON [dbo].[order_details]
FOR INSERT
AS

insert into information(order_item_id,mfg_status)
select pkCOl, 'nothing' from inserted



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2009-08-06 : 14:21:14
thanks :)
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2009-08-09 : 05:27:26
How can I have the trigger above first count if any records exits with that order_item_id and only add if no record exists?

Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-08-09 : 05:50:18
insert into information(order_item_id,mfg_status)
select DISTINCT pkCOl, 'nothing' from inserted
where not exists(select * from information where order_item_id=inserted.pkCOl)


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2009-09-16 : 15:27:23
tried to use this somewhere else
what am i doing wrong

alter TRIGGER insertex ON [dbo].[transcations]
FOR INSERT
AS
declare @transactionid int
select @transactionid=id from inserted
exec spinsertex @transactionid

I get an error Invalid object name 'inserted'
Go to Top of Page
   

- Advertisement -