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 2000 Forums
 Transact-SQL (2000)
 Help with INSERT trigger

Author  Topic 

raxbat
Yak Posting Veteran

52 Posts

Posted - 2007-12-14 : 09:17:12
Hello all!
I want optimize my table!
currently situation(fragment form table):

datetime Value
14/12/2007 09:01:01 1
14/12/2007 09:01:02 1
14/12/2007 09:01:03 1
14/12/2007 09:01:04 2
14/12/2007 09:01:05 2
14/12/2007 09:01:06 2
14/12/2007 09:01:07 2
14/12/2007 09:01:08 2
14/12/2007 09:01:09 2

I want trigger to control the data, for example: do not insert a row, if the Value is the same as previous, but time is different!

Thanx for any help






visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2007-12-14 : 11:43:07
You can do this by means of an INSTEAD OF INSERT trigger
something like:-

CREATE TRIGGER T_{tablename} ON {tablename}
INSTEAD OF INSERT AS
BEGIN
IF NOT EXISTS (SELECT * FROM {table} t
INNER JOIN INSERTED i
ON i.Value=t.Value)
BEGIN
INSERT INTO table(datetime,Value)
SELECT datetime,Value
FROM inserted
END
Go to Top of Page

raxbat
Yak Posting Veteran

52 Posts

Posted - 2007-12-14 : 14:29:18
Thanx. But I have an error when checking syntax:
Incorect syntax near END
Go to Top of Page

Van
Constraint Violating Yak Guru

462 Posts

Posted - 2007-12-14 : 14:32:35
You have 2 BEGIN's, need two END's
Go to Top of Page
   

- Advertisement -