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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data from instered row in Trigger

Status
Not open for further replies.

thattoo

Technical User
Dec 15, 2004
6
BE
Whenever I have a row inserted in a table, I want a trigger procedure to insert a row into another tabel with data from the first insterted row.
I thought it would be like this:

CREATE TRIGGER AddReferalmail
ON tblLeider
FOR INSERT
AS
INSERT INTO tblMail (Mail_ID, HagelMail)
VALUES (NEW.Leider_Id, New.Voornaam + '.' + New.Achternaam + '@Hagelstein.be')
GO

But this gives me the following error:
Server: Msg 128, Level 15, State 1, Procedure AddReferalmail, Line 6
The name 'Leider_Id' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.

I use SQL Server 2000
 
in the first place, you never, ever write a trigger using the values clause of an insert statment because it will fail if you ever insert multiple records.

SQl Server triggers have two pseudotables, inserted and delted. If you are trying to get the new values to insert into another table use the inserted table (deleted contains the old values)
Code:
Insert into table2 (field1, field2)
select field1, field2 from inserted

Questions about posting. See faq183-874
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top