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
 General SQL Server Forums
 New to SQL Server Programming
 After insert trigger

Author  Topic 

eaglecoug
Starting Member

1 Post

Posted - 2012-12-28 : 14:04:02
Trying to create trigger where if GPA is within range then need to add new tuple inserted into another table. So my question is after begin, how do I tell SQL to insert the new sID (new sID initially inserted into Student table) into Apply table?

create trigger R1
on Student
after insert
as
if exists (select GPA from Student where GPA > 3.3 and GPA <=3.6)

begin
insert into Apply values (sID, 'Stanford',
'geology', null);
insert into Apply values (sID, 'MIT', 'biology', null);
end;


I get this error when I try to execute:

Msg 4104, Level 16, State 1, Procedure R1, Line 8
The multi-part identifier "Apply.sID" could not be bound.
Msg 4104, Level 16, State 1, Procedure R1, Line 10
The multi-part identifier "Apply.sID" could not be bound.

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2012-12-28 : 14:34:54
You can't directly insert into Appy table from trigger. After you make insert into Student table trigger will store the information in Virtual table (inserted) and then will insert into apply table

create trigger R1
on Student
after insert
as
IF Exists (select GPA from Student where GPA > 3.3 and GPA <=3.6)

begin
insert into Apply
Select <columns> from inserted
end
Go to Top of Page
   

- Advertisement -