Solved

Trigger on UPDATE with multiple conditions

Posted on 2007-03-27
2
175 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

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.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

706 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

18 Experts available now in Live!

Get 1:1 Help Now