Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Building a Trigger with Two Conditions

Status
Not open for further replies.

SeaninSeattle

IS-IT--Management
Sep 17, 2001
53
US
Ok - I really need some help. I'm trying to build a trigger on a table that with every insertion will look at the record inserted, and then, if it meets two condtions (SOPTYPE 2 and today's date in DOCDATE), will kick out an email via SQL Mail. This is what I have:
===============================

USE BSW2

/* delete any existing version of this trigger before attempting to create */

if exists
(select * from dbo.sysobjects
where id = object_id(N'[dbo].[EmailTR_SOP10100InsTrg]')
and OBJECTPROPERTY(id, N'IsTrigger') = 1)
drop trigger [dbo].[EmailTR_SOP10100InsTrg]


GO
CREATE TRIGGER EmailTR_SOP10100InsTrg
ON [SOP10100]
FOR INSERT
AS
EXEC master..xp_sendmail 'SeanE', 'Table has been hit by SOPTYPE2!'
IF SOPTYPE = 2 and
SOP10100.SOPNUMBE in
(Select SOPNUMBE from SOP10100
where (Select convert(char(10),DOCDATE,1))
= (Select convert(char(10),getdate (),1)))

GO
================================
I keep getting a failure message on this telling me that there is a syntax error on the last line by ')'.

Any ideas??

Thanks in advance! :)

//sse
Sean Engle
Admin/DirIS
ssengle@bswusa.com
 
CREATE TRIGGER EmailTR_SOP10100InsTrg
ON SOP10100
FOR INSERT
AS

if exists (
select * from inserted
where SOPTYPE = 2
and datediff(day,docdate, getdate()) = 0 )
EXEC master..xp_sendmail 'SeanE', 'Table has been hit by SOPTYPE2!'
 
Thanks for your help! Sean Engle
Admin/DirIS
ssengle@bswusa.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top