Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Trigger with Multiple Conditions
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Conception bases de données
Divers
Thread ID:
00758376
Message ID:
00758385
Vues:
20
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--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform