Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 adding conditional logic inside a trigger

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-04-27 : 08:59:53
Mike writes "I wrote a trigger that works just fine and then I realized I need to add a little bit more logic to it but I haven't been successful. Heres the trigger that works so far:

CREATE TRIGGER updateGrandTotal ON [dbo].[orders]
FOR INSERT, UPDATE
AS
Update [dbo].[orders] set
grandTotal = isNull(catalogSubtotal,0) + isNull(primerSubtotal,0) + isNull(tax,0) + isNull(catalogFreight,0) + isNull(catalogIce,0) + isNull(primerFreight,0)
Where OrdersID = (Select OrdersID from Inserted)

I need some sort of logic added above that will achieve the following:

If shippingCalculatedBy = 'ERP'
grandTotal = 0
else
grandTotal = catalogSubTotal + primerSubTotal
If freightFlag then add catalogFreight and primerFreight to grandTotal
If iceFlag then add catalogIce to grandTotal

Got any ideas?"

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-04-27 : 09:14:50
Sounds like you need a case statement on the right side of your SET clause.

Jay White
{0}
Go to Top of Page
   

- Advertisement -