Showing posts with label threw. Show all posts
Showing posts with label threw. Show all posts

Friday, March 9, 2012

i am having an issue with my trigger code

i am having an issue with my trigger code
i believe that i should be able to use the multiple if else statements
and i just threw in an update in each begin end statement
but when i check the syntax it fails

any reason why that is
CREATE TRIGGER [tr_update_conveyor_interface] ON [dbo].[t_conveyor_interface]
FOR UPDATE
AS

declare
@.id integer,
@.barcode varchar(25),
@.epc_tag varchar(24),
@.reject_flag char(1),
@.hold_flag char(1),
@.pe_3_flag char(1),
@.old_id integer,
@.old_barcode varchar(25),
@.old_epc_tag varchar(24),
@.old_reject_flag char(1),
@.old_hold_flag char(1),
@.old_pe_3_flag char(1)

select @.barcode = c.barcode,
@.id = c.id,
@.epc_tag = c.epc_tag,
@.reject_flag = c.reject_flag,
@.hold_flag = c.hold_flag,
@.pe_3_flag = c.pe_3_flag
from t_conveyor_interface c
inner join deleted d
on c.barcode = d.barcode

select @.old_barcode = c.barcode,
@.old_id = c.id,
@.old_epc_tag = c.epc_tag,
@.old_reject_flag = c.reject_flag,
@.old_hold_flag = c.hold_flag,
@.old_pe_3_flag = c.pe_3_flag
from t_conveyor_interface c
inner join inserted i
on c.barcode = i.barcode

if(@.old_epc_tag <> @.epc_tag)
begin
update t_load_audit
set id = 1
end

else
if(@.old_reject_flag <> @.reject_flag)
begin
update t_load_audit
set id = 1
end

else
if(@.old_hold_flag <> @.hold_flag)
begin
update t_load_audit
set id = 1
end

else
if(@.old_pe_3_flag <> @.pe_3_flag
begin
update t_load_audit
set id = 1
endNevermind, I got it