Link to home
Start Free TrialLog in
Avatar of HKFuey
HKFueyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

SQL Trigger Syntax

Hi,

I have this trigger: -
ALTER TRIGGER [dbo].[InvMasterSetOnHoldStatus]
   ON  [dbo].[InvMaster]
   AFTER INSERT
AS 
    UPDATE dbo.InvMaster
       SET StockOnHold = 'F'
         , StockOnHoldReason = 'NEW'    
      WHERE StockCode in (SELECT StockCode FROM Inserted WHERE (WarehouseToUse <> 'R ' AND WarehouseToUse <> 'W '));

Open in new window


I want it to fire when WarehouseToUse  is not R or W.

When I click submit, I just get an hourglass, does anyone know where I'm going wrong?
Avatar of gplana
gplana
Flag of Spain image

Try this:

CREATE OR REPLACE TRIGGER [dbo].[InvMasterSetOnHoldStatus]
   AFTER INSERT ON  [dbo].[InvMaster]
AS 
    UPDATE dbo.InvMaster
       SET StockOnHold = 'F'
         , StockOnHoldReason = 'NEW'    
      WHERE StockCode in (SELECT StockCode FROM Inserted WHERE (WarehouseToUse <> 'R ' AND WarehouseToUse <> 'W '));
END
GO

Open in new window

Avatar of HKFuey

ASKER

Hi gplana Result is this: -
Msg 156, Level 15, State 1, Line 8
Incorrect syntax near the keyword 'OR'.
Msg 102, Level 15, State 1, Line 15
Incorrect syntax near 'END'.
SOLUTION
Avatar of Peter Chan
Peter Chan
Flag of Hong Kong image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of HKFuey

ASKER

Thanks for the help on this.