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)
 Please help with trigger error...

Author  Topic 

keuler
Starting Member

10 Posts

Posted - 2008-03-04 : 11:28:26
All-

The following trigger is in a table called "PERSON". When I attempt to save it (not even testing it yet), I get the message "Incorrect syntaxt near 'GO'". Please advise as to what the error might be.


CREATE TRIGGER InsertHeadCount
ON dbo.person
AFTER INSERT
AS
INSERT INTO
HEADCOUNT(person_id,activity_id,no_answer,not_coming,coming)
SELECT i.person_id,a.activity_id,1,0,0
FROM INSERTED i
CROSS JOIN ACTIVITY a
GO


Background: I'm building an application that includes tables PERSON, ACTIVITY, and HEADCOUNT that look like this:

PERSON
person_id (int)
person_name (varchar(50))
...etc

ACTIVITY
activity_id (int)
activity_name (varchar(50))
no_answer (bit)
not_coming (bit)
coming (bit)

HEADCOUNT
headcount_id (int)
member_id (int)
activity_id (int)
...etc


The intended functionality of the trigger is as follows: Suppose that:

a) The ACTIVITY table is already populated with several records, say with activity_id = 1, 2, and 3.
b) The HEADCOUNT table is already populated with 30 records.

TRIGGER OBJECTIVE: When a new record is added to the PERSON, say with person_id= 10, insert one record in the HEADCOUNT table FOR EACH activity in the ACTIVITY table for that person. Thus, if person #10 is added to the PERSON table, then the trigger would add the following records to the HEADCOUNT table:

headcount_id person_id activity_id
31 10 1
32 10 2
33 10 3

Thanks a lot in advance for your assistance!!!

-Kurt

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-03-04 : 11:44:27
Cant find out any problems with your code.Are you sure you're getting this error?
Go to Top of Page

keuler
Starting Member

10 Posts

Posted - 2008-03-04 : 12:14:24
Visakh- I'm pretty sure. I'll give it another try soon.

Note: In case it matters, I created this trigger within Visual Web Developer 2008, thouugh the Database Explorer area.

Thanks for your continued help!

-Kurt
Go to Top of Page
   

- Advertisement -