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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trigger send email on new record

Status
Not open for further replies.

RJL1

Technical User
Oct 3, 2002
228
US
Hello,

I'm working on the following trigger which should send an email when a new record is created. The new record is created when a shipment is back order.

I'm new to triggers so I'm not sure this is correct but whe nI try to create the trigger I get the following error

Incorrect syntax near '@SHIPMENT_ID'.
Must declare the scalar variable "@SHIPMENT_ID".

Code:
CREATE TRIGGER WEPK_BACKORDER_EMAIL
 ON WEPK_SHIPMENT_BACKORDER
 AFTER INSERT

AS
BEGIN

@SHIPMENT_ID NVARCHAR(25),
@BODY VARCHAR(500)

SELECT @SHIPMENT_ID = I.SHIPMENT_ID

FROM INSERTED I

SET @BODY = 'Shipment Number ' @SHIPMENT_ID ' has been back order'

EXEC MASTER.XP_SENDMAIL
 @RECIPIENTS = 'user@domain.com,
 @SUBJECT = 'Shipment Backorder',
 @MESSAGE = 'Shipment Number '@SHIPMENT_ID' has been back order'

END

Any help with this is appreciated
RJL1
 
Thanks markros, as alway very good feedback. Articles were great and based on them I took a different approach and I have the triogger to write to the new table done and will tackle the email in a different way (with a schedule task)

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top