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.
Author |
Topic |
hspatil31
Posting Yak Master
182 Posts |
Posted - 2009-04-08 : 00:50:52
|
Dear Freind,In the following Trigger all values not saved in database. Means i want to fire this Trigger before Insert or Update. Can anybody suggest me what is change in that Trigger.ALTER TRIGGER AmountForPCTitleON dbo.ORDRAFTER INSERT, UPDATE ASSET NOCOUNT ONUPDATE xSET x.DocTotal = COALESCE(i.DocTotalSy, 0) + COALESCE(i.U_Ref, 0) + COALESCE(i.U_Sub, 0)FROM dbo.ORDR AS xINNER JOIN inserted AS i ON i.DocEntry = x.DocEntryThanks Harish |
|
svicky9
Posting Yak Master
232 Posts |
Posted - 2009-04-08 : 03:13:51
|
I am assuming you want to do something before you update or insert the table. In the above code, use the For Trigger and add the Insert Statement after your Trigger Update Code.ALTER TRIGGER AmountForPCTitleON dbo.ORDRFOR INSERT,UPDATEASSET NOCOUNT ONBeginUPDATE xSET x.DocTotal = COALESCE(i.DocTotalSy, 0) + COALESCE(i.U_Ref, 0) + COALESCE(i.U_Sub, 0)FROM dbo.ORDR AS xINNER JOIN inserted AS i ON i.DocEntry = x.DocEntry<Your Insert goes here>EndHope this helpshttp://www.sqlserver007.com |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-04-08 : 03:19:53
|
What do you mean with "all values not saved in database"? E 12°55'05.63"N 56°04'39.26" |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-04-10 : 06:46:25
|
quote: Originally posted by hspatil31 Dear Freind,In the following Trigger all values not saved in database. Means i want to fire this Trigger before Insert or Update. Can anybody suggest me what is change in that Trigger.ALTER TRIGGER AmountForPCTitleON dbo.ORDRINSTEAD OF AFTER INSERT, UPDATE ASSET NOCOUNT ONUPDATE xSET x.DocTotal = COALESCE(i.DocTotalSy, 0) + COALESCE(i.U_Ref, 0) + COALESCE(i.U_Sub, 0)FROM dbo.ORDR AS xINNER JOIN inserted AS i ON i.DocEntry = x.DocEntryThanks Harish
if you want to fire trigger before insert/update use INSTEAD OF rather than AFTER |
 |
|
|
|
|
|
|