May 23, 2013 at 11:35 am
SQL2000
Need help with triggers. I'm trying to create a trigger that checks the table; if the record exists based on a few criterias, then it won't insert, otherwise insert it.
This is my attempt following http://www.sqlservercentral.com/articles/Triggers/64214
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF EXISTS (SELECT name FROM sysobjects
WHERE name = 'BI_XYZ_TRI' AND type = 'TR')
DROP TRIGGER BI_XYZ_TRI
GO
CREATE TRIGGER BI_XYZ_TRI
ON XYZ
INSTEAD OF INSERT
AS
BEGIN
SET NOCOUNT ON;
IF NOT EXISTS (SELECT * FROM inserted a JOIN xyz b
ON a.criteria1 = b.criteria1
AND a.criteria2 = b.criteria2
AND a.criteria3 = b.criteria1
AND a.criteria4 = b.criteria1
AND a.criteria5 = b.criteria5)
BEGIN
INSERT INTO dbo.xyz
( col1,
col2,
col3,
col4,
col5,
...
)
SELECT col1,
col2,
col3,
col4,
col5,
...
FROM inserted
END -- ends insert sttmt
ELSE
BEGIN
RAISERROR ('Duplicate Records')
END -- ends raiserror
END -- ends trigger
GO
I'm getting error
Incorrect syntax near ')'
Can anyone help? Thank you
May 23, 2013 at 11:47 am
pretty sure RAISERROR requires three parameters, and you only passed one.
RAISERROR ('Duplicate Records',16,1)
Lowell
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply