?
Solved

Trigger on UPDATE with multiple conditions

Posted on 2007-03-27
2
Medium Priority
?
183 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
[X]
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
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

777 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