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
 SQL Server Development (2000)
 Trigger Help

Author  Topic 

grueneic
Starting Member

3 Posts

Posted - 2002-05-29 : 10:09:00
Below is a trigger I am working on. I am receiving several errors and do not know how to resolve. One of the Errors is the line that says 'IF @ClearBy IS NULL' There are also other errors with the IF statement. Please help. I am new at this.


CREATE Trigger trg_employees
On dbo.TROUBLE
For Update
AS

Declare @Comment nvarchar(1000)
Declare @TechnicianRemarks nvarchar(1000)
Declare @ClearBy nvarchar(25)
Declare @ClearDate datetime
Declare @ClearTime datetime
Declare @Type nvarchar(50)

Select @Comment = Comment FROM INSERTED
Select @TechnicianRemarks = Resolution FROM INSERTED
Select @ClearBy = ClearBy FROM INSERTED
Select @ClearDate = ClearDate FROM INSERTED
Select @ClearTime = ClearTime FROM INSERTED
Select @Type = Type FROM INSERTED

/*Check to see if the ClearBy field is NULL. We only want to send an email
if the ClearByField is NOT NULL.
*/
IF @ClearBy IS NULL
BEGIN
--do nothing
END

ELSE
--Now Check to see if the ticket is a Service Order (SO) or a Trouble Ticket (TR)
IF @Type = 'SO'
BEGIN


END

Kevin Snow
Posting Yak Master

149 Posts

Posted - 2002-05-29 : 10:21:51
IF @ClearBy IS NULL
BEGIN
--do nothing
END

You may need parentheses

IF NOT(@ClearBy IS NULL )

Also, the SQL Parser does not allow empty BEGIN END blocks
Eliminate them, or put in a temporary 'filler' step.

BEGIN
Select @ClearBY
END
Go to Top of Page

smccreadie
Aged Yak Warrior

505 Posts

Posted - 2002-05-29 : 10:23:19
SQL is looking for a statement between the BEGIN and END tags. A comment won't work. Change you code to this:

 

CREATE Trigger trg_employees
On dbo.TROUBLE
For Update
AS

Declare @Comment nvarchar(1000)
Declare @TechnicianRemarks nvarchar(1000)
Declare @ClearBy nvarchar(25)
Declare @ClearDate datetime
Declare @ClearTime datetime
Declare @Type nvarchar(50)

Select @Comment = Comment FROM INSERTED
Select @TechnicianRemarks = Resolution FROM INSERTED
Select @ClearBy = ClearBy FROM INSERTED
Select @ClearDate = ClearDate FROM INSERTED
Select @ClearTime = ClearTime FROM INSERTED
Select @Type = Type FROM INSERTED

/*Check to see if the ClearBy field is NULL. We only want to send an email
if the ClearByField is NOT NULL.
*/
IF @ClearBy IS NOT NULL
--Now Check to see if the ticket is a Service Order (SO) or a Trouble Ticket (TR)
IF @Type = 'SO'
BEGIN
...statement here...
END



Go to Top of Page

grueneic
Starting Member

3 Posts

Posted - 2002-05-29 : 10:25:14
THANK YOU. IT NOW WORKS

Go to Top of Page
   

- Advertisement -