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
 General SQL Server Forums
 New to SQL Server Programming
 how to create Triggers

Author  Topic 

aamir1
Starting Member

2 Posts

Posted - 2006-12-08 : 00:20:41
hy guys
i m trying to create trigger but i tired to get an error msg

trigger which i want to create is :

CREATE TRIGGER TR_TESTING ON EMPLOYEES
FOR INSERT
AS
DECLARE @TMP AS VARCHAR(1)
SET @TMP=SUBSTRING(FirstName,0,1) FROM EMPLOYEES
IF @TMP='A'
BEGIN
INSERT INTO EMPLOYEES(LastName,FirstName) VALUES('DHARANI','AAMIR')
END
ELSE
BEGIN
PRINT 'INSERT VALID RECORD'
END

**** but i got an error msg

Incorrect syntax near the keyword 'FROM'.

plz guide me abt this problem as soon as possible

madhuotp
Yak Posting Veteran

78 Posts

Posted - 2006-12-08 : 00:28:41
it should be Select instead of SET

For :
SET @TMP=SUBSTRING(FirstName,0,1) FROM EMPLOYEES
Read
Select @TMP=SUBSTRING(FirstName,0,1) FROM EMPLOYEES


Madhu
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-12-08 : 02:41:19
<<
SET @TMP=SUBSTRING(FirstName,0,1) FROM EMPLOYEES
>>

1 Use SELECT if you want to assign value to variable from table
2 Make sure the query returns only one value

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -