473,396 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

trigger - Incorrect syntax near 'INSTEAD' error

Running under SQL2000 I can not get an INSTEAD trigger to function. I've even copied the example directl from books online - no joy . . .

Server: Msg 170, Level 15, State 1, Procedure IO_Trig_INS_Employee, Line 2
Line 2: Incorrect syntax near 'INSTEAD'.

CREATE TABLE Person
(
SSN char(11) PRIMARY KEY,
Name nvarchar(100),
Address nvarchar(100),
Birthdate datetime
)

CREATE TABLE EmployeeTable
(
EmployeeID int PRIMARY KEY,
SSN char(11) UNIQUE,
Department nvarchar(10),
Salary money,
CONSTRAINT FKEmpPer FOREIGN KEY (SSN)
REFERENCES Person (SSN)
)

CREATE VIEW Employee AS
SELECT P.SSN as SSN, Name, Address,
Birthdate, EmployeeID, Department, Salary
FROM Person P, EmployeeTable E
WHERE P.SSN = E.SSN

CREATE TABLE PersonDuplicates
(
SSN char(11),
Name nvarchar(100),
Address nvarchar(100),
Birthdate datetime,
InsertSNAME nchar(100),
WhenInserted datetime
)

CREATE TRIGGER IO_Trig_INS_Employee ON Employee
INSTEAD OF INSERT
AS
BEGIN
SET NOCOUNT ON
-- Check for duplicate Person. If no duplicate, do an insert.
IF (NOT EXISTS (SELECT P.SSN
FROM Person P, inserted I
WHERE P.SSN = I.SSN))
INSERT INTO Person
SELECT SSN,Name,Address,Birthdate,Comment
FROM inserted
ELSE
-- Log attempt to insert duplicate Person row in PersonDuplicates table.
INSERT INTO PersonDuplicates
SELECT SSN,Name,Address,Birthdate,SUSER_SNAME(),GETDATE()
FROM inserted
-- Check for duplicate Employee. If no duplicate, do an insert.
IF (NOT EXISTS (SELECT E.SSN
FROM EmployeeTable E, inserted
WHERE E.SSN = inserted.SSN))
INSERT INTO EmployeeTable
SELECT EmployeeID,SSN, Department, Salary,Comment
FROM inserted
ELSE
--If duplicate, change to UPDATE so that there will not
--be a duplicate key violation error.
UPDATE EmployeeTable
SET EmployeeID = I.EmployeeID,
Department = I.Department,
Salary = I.Salary,
Comment = I.Comment
FROM EmployeeTable E, inserted I
WHERE E.SSN = I.SSN
END
Jul 9 '08 #1
1 3172
ck9663
2,878 Expert 2GB
Here's the error if your run it in sql2005

Msg 207, Level 16, State 1, Procedure IO_Trig_INS_Employee, Line 12
Invalid column name 'Comment'.
Msg 213, Level 16, State 1, Procedure IO_Trig_INS_Employee, Line 12
Insert Error: Column name or number of supplied values does not match table definition.
-- CK
Jul 9 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Fernand St-Georges | last post by:
Hi, can someone tell how to write a Trigger; I am familiar with Sybase Sql Anywhere trigger syntax. Actually I have three tables MEMBER, CONTRACT and PAYMENT I need to update the MEMBER.BALANCE...
2
by: William F. O'Neill | last post by:
Am using SQL Server 2000 on WINXP Pro. Have a requirement to change some Oracle triggers to SQL 2000. I have modied this one Insert Trigger, but get an error when I attempt to compile: CREATE...
2
by: MrMike | last post by:
I'm building this trigger and an error message is appearing which says: " Error 170: Incorrect Syntax: Line 6 near "=". Could someone please help me understand why this error is occuring? Thanks....
10
by: Axel | last post by:
Hello, I would like to create a (what I believe is) simple trigger that updates a row in one table based on updates of corresponding fields of same row. Its a "week total" field that sums up...
3
by: Axel | last post by:
Hello, I have detail sections in several subforms that are used to fill daily order data per product. Each row contains textboxes for the weekdays and a locked textbox (txtTotal) for the week's...
2
by: R.A.M. | last post by:
Hello, I am learning SQL Server 2005. I need to create a trigger which increments number of book's publications: CREATE TRIGGER InsertPublication ON Publications AFTER INSERT AS BEGIN
0
by: roamnet | last post by:
hi i created database file with .mdf extention ,sql server as a source and use grid view to display data there're no problem in data retrieve and display,but i want to edit it or insert new...
3
by: ramesh1210 | last post by:
please help me, I had created a table, CREATE TABLE THETABLE ( id_num int IDENTITY(1,1), DT datetime, NM varchar(30) )
4
zachster17
by: zachster17 | last post by:
Hello all, I have 2 tables (tblAddProviderProfessional and tblAddProvider). There are other tables such as tblAddProviderFacility and so forth. tblAddProvider is a table that has similar data...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.