Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trigger to pass Param to SP 1

Status
Not open for further replies.

MadBnz

Technical User
Jan 30, 2002
18
NZ
Hi, I have a SP that accepts a Value (item_id) and then creates a folder under its name. Is there anyway with an Insert Trigger to call the SP and pass the value? something like?

sp_itemFolder item_id
From Inserted
 
You could try:

create trigger tr_insert_table on table
for Insert
on
declare @item varchar(50)
select @item = inserted.item_id from inserted

exec sp_itemFolder @item_id


If you have multiple items, I think you will have to use a cursor.. BAD thing to have in triggers. But this would work:

create trigger tr_insert_table on table
for insert
on
create trigger tr_insert_table on table
for Insert
on
declare @item varchar(50)
declare loop_var cursor for
select inserted.item_id from inserted
open loop_var
fetch next from loop_var into @item
while @@fetch_status = 0
begin
exec sp_itemFolder @item
fetch next from loop_var into @item
end
close loop_var
deallocate loop_var


Hope this helps.
 
Thanks, I used your top example as there is only one item inserted at a time, and it worked a treat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top