dbTalk Databases Forums  

trigger help

microsoft.public.sqlserver.server microsoft.public.sqlserver.server


Discuss trigger help in the microsoft.public.sqlserver.server forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Matt
 
Posts: n/a

Default trigger help - 12-18-2005 , 08:59 AM







Greetings,
I am having some trouble with a trigger. This is my first attempt at
creating a trigger so any help would be great. The function of the
trigger is, on the insert of a row to check the value inserted into to
column VEH_REPAIR_CODE. If that value is not 19, send an email to the
value inserted in column VEH_CREW_CK_LANID. The email would include
the values inserted from columns VEH_CREW_CK_LANID and
VEHICLE_CHECK_ID ( the primary key of the table so the value is
inserted from the system). If have the following syntax but it does
not seem to work.

Thank you for any help you can provide.

CREATE TRIGGER car_check_repair_insert ON dbo. VEHICLE_CHECK FOR
INSERT AS
BEGIN
DECLARE @CREW_1 VARCHAR(20)
DECLARE @UNIT_1 VARCHAR(20)
DECLARE @VEH_REPAIR_CODE INT

DECLARE @MCC_ID VARCHAR(10)
BEGIN
SELECT @VEH_REPAIR_CODE = INSERTED.VEH_REPAIR_CODE, @CREW_1 =
INSERTED.VEH_CREW_CK_LANID, @UNIT_1 = INSERTED.VEHICLE_NUM,@MCC_ID=
VEHICLE_CHECK_ID
From INSERTED
IF @VEH_REPAIR_CODE <> 19
BEGIN
--Send the email here
DECLARE @MAIL_TO VARCHAR(50)
DECLARE @AUNIT VARCHAR(150)
DECLARE @MCID VARCHAR(20)

SELECT @MAIL_TO = @CREW_1 + '@exrch.site.com',@AUNIT ='unit
number ' + @UNIT_1 + ' Reference number ' + @MCID '
exec master.dbo.xp_sendmail @recipients = @MAIL_TO,
@message = @AUNIT,
@subject = 'car check'


END
END
END

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.