Solved

Trigger on UPDATE with multiple conditions

Posted on 2007-03-27
2
177 Views
Last Modified: 2010-03-19
I have a table called OrderQuote and quite simply I need a trigger that does the following on UPDATE (its not needed on INSERT

if  (orqu_nettamt > '250000' OR orqu_overallmargin < '1') AND orqu_authby IS NULL
UPDATE OrderQuote SET orqu_authorisation='Pending' else orqu_authorisation='NA'

But if the (OrQu_nettamt > '250000' OR OrQu_overallmargin < '1') AND orqu_authby IS NOT NULL
Set the orqu_authorisation='Yes'

Cheers,

Mim
0
Comment
Question by:MimUK
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 125 total points
ID: 18802031
CREATE TRIGGER TRG_UPD_OrderQuote
ON OrderQuote
FOR UPDATE
AS
  UPDATE OrderQuote
       SET orqu_authorisation= CASE
           WHEN (i.OrQu_nettamt > 250000 OR i.OrQu_overallmargin < 1 ) AND i.orqu_authby IS NOT NULL
            THEN 'Yes'
            WHEN (i.orqu_nettamt > 250000 OR i.orqu_overallmargin < 1) AND i.orqu_authby IS NULL
             THEN 'Pending'
             ELSE 'NA'  END
   FROM OrderQuote q
   JOIN inserted i
       ON i.ID = q.ID
           
0
 

Author Comment

by:MimUK
ID: 18802110
Brilliant, tested and works flawlessly
Thanks angelIII

Points awarded
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how the fundamental information of how to create a table.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now