Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Trigger on UPDATE with multiple conditions

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

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

860 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