SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 After insert trigger
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

eaglecoug
Starting Member

USA
1 Posts

Posted - 12/28/2012 :  14:04:02  Show Profile  Reply with Quote
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.

Edited by - eaglecoug on 12/28/2012 14:06:02

sodeep
Flowing Fount of Yak Knowledge

USA
7174 Posts

Posted - 12/28/2012 :  14:34:54  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000