Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Trigger with Multiple Conditions
Message
General information
Forum:
Microsoft SQL Server
Category:
Database design
Miscellaneous
Thread ID:
00758376
Message ID:
00758385
Views:
15
This message has been marked as a message which has helped to the initial question of the thread.
Hi Justin,

You didn't tell what the problem is so I'll have to guess.
First, I think you would want to use SYSTEM_USER instead of user_name(). See BOL for details.
Second, you should use AND instead of OR in the IF.
IF (SELECT SYSTEM_USER <> 'BackEnd' 
  AND (select cOrderType from deleted) <> 'X' 
  AND (select cOrderType from inserted) <> 'X'
>Hello,
>
>We are using a trigger that updates a date field on two tables every time one of those tables is updated. We do not want the trigger to fire if the user_name is BackEnd, or if Order.cOrderType has been changed to or changed from an 'X'. The following is the code:
>
>CREATE TRIGGER OrderEdit ON dbo.Order
>FOR INSERT, UPDATE
>AS
>IF (SELECT user_name()) <> 'BackEnd' 
  or (select cOrderType from deleted) <> 'X' 
  or (select cOrderType from inserted) <> 'X'
>	BEGIN	
>		UPDATE dbo.Order
>			SET tEdited = GETDATE()
>			WHERE iOrder IN
>			(SELECT iOrder FROM inserted)
>		UPDATE dbo.Customer
>			SET tEdited = GETDATE()
>			WHERE iCustomer IN
>			(SELECT iCustomer FROM inserted)
>	END
>I have also tried nesting the IF statements and failed.
>
>TIA
>
>-Justin
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform