christine1
MIS
Good morning,
I'm trying to create an Insert/Update trigger (see trig below)Here's what I want to do: If the record does not exist in the inserted table then insert into cube_control_tbl, if it does and the record has changed then update. What am I doing wrong???
Please help I have to have this by noon.
Signed brain fried
CREATE TRIGGER manual_control_trig ON dbo.CUBE_CONTROL
FOR INSERT,UPDATE
AS
IF UPDATE
(select * from header_view hi, inserted i
where hi.phys_piece = i.phys_piece)
DECLARE
@company company,
@site site,
@plant plant,
@design design,
@serial_num serial_num,
@phys_piece phys_piece,
@last_ops last_ops,
@manual_control manual_control,
@last_rep_date last_rep_date
INSERT INTO CUBE_CONTROL
(COMPANY, SITE, PLANT, DESIGN, UNIT, SERIAL_NUM, PHYS_PIECE, LAST_OPS,
MANUAL_CONTROL, LAST_REP_DATE)
VALUES (@COMPANY, @SITE, @PLANT, @DESIGN, @UNIT, @SERIAL_NUM, @PHYS_PIECE, @LAST_OPS,
@MANUAL_CONTROL, @LAST_REP_DATE)
UPDATE CUBE_CONTROL
SET i.last_rep_date = i.last_ops
FROM header_view hi, inserted i
WHERE i.manual_control = 'N'
AND hi.phys_piece = i.phys_piece
GO [sig][/sig]
I'm trying to create an Insert/Update trigger (see trig below)Here's what I want to do: If the record does not exist in the inserted table then insert into cube_control_tbl, if it does and the record has changed then update. What am I doing wrong???
Please help I have to have this by noon.
Signed brain fried
CREATE TRIGGER manual_control_trig ON dbo.CUBE_CONTROL
FOR INSERT,UPDATE
AS
IF UPDATE
(select * from header_view hi, inserted i
where hi.phys_piece = i.phys_piece)
DECLARE
@company company,
@site site,
@plant plant,
@design design,
@serial_num serial_num,
@phys_piece phys_piece,
@last_ops last_ops,
@manual_control manual_control,
@last_rep_date last_rep_date
INSERT INTO CUBE_CONTROL
(COMPANY, SITE, PLANT, DESIGN, UNIT, SERIAL_NUM, PHYS_PIECE, LAST_OPS,
MANUAL_CONTROL, LAST_REP_DATE)
VALUES (@COMPANY, @SITE, @PLANT, @DESIGN, @UNIT, @SERIAL_NUM, @PHYS_PIECE, @LAST_OPS,
@MANUAL_CONTROL, @LAST_REP_DATE)
UPDATE CUBE_CONTROL
SET i.last_rep_date = i.last_ops
FROM header_view hi, inserted i
WHERE i.manual_control = 'N'
AND hi.phys_piece = i.phys_piece
GO [sig][/sig]