Solved

Trigger on UPDATE with multiple conditions

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

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Call to SQL server times out 5 50
SQL Convert rows to columns 5 31
Any benefit to adding a Clustered index here? 4 34
Do not display comma when no last name 8 46
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.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how the fundamental information of how to create a table.

738 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