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 |
perimidt
Starting Member
4 Posts |
Posted - 2014-05-19 : 06:13:36
|
Hi I am trying to update one table when records are inserted in another table.I have added the following trigger to the table “ProdTr” and every time a record is added I want to update the field “Qty3” in the table “ActInf” with a value from the inserted record.My problem appears to be that I am unable to fill the variables with values, and I cannot understand why it isn’t working, my code is:ALTER trigger [dbo].[antall_liter] on [dbo].[ProdTr]for insertas begindeclare @liter as decimal(28,6) declare @kundenr as intdeclare @aktor as intselect @kundenr = CustNo from insertedselect @liter = NoInvoAb from insertedselect @aktor = [ActNo] from [Actor] where [Actor].[CustNo] = @kundenrupdate [ActInf] set Qty3 = Qty3 + @literwhere ActNo = @aktorend Any tips would be very appreciated.Best regardsPer Erik Midtrød |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2014-05-19 : 08:09:37
|
[code]ALTER trigger [dbo].[antall_liter] on [dbo].[ProdTr]for insertas beginUPDATE bSET Qty3 = Qty3 + i.NoInvoAb FROM inserted iINNER JOIN Actor a ON i.CustNo = a.CustNo INNER JOIN [ActInf] b ON a.ActNo = b.ActNoend[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
perimidt
Starting Member
4 Posts |
Posted - 2014-05-19 : 08:25:34
|
Thanks for the suggestion, but I still cannot get it update the table ActInf.Best regardsPer Erik Midtrød |
 |
|
perimidt
Starting Member
4 Posts |
Posted - 2014-05-19 : 08:35:26
|
Never mind, when I add a record manually in the database it works, apparently there is something that stops the trigger when data is added from the ERP-system which is supposed to do this.quote: Originally posted by perimidt Thanks for the suggestion, but I still cannot get it update the table ActInf.Best regardsPer Erik Midtrød
Best regardsPer Erik Midtrød |
 |
|
perimidt
Starting Member
4 Posts |
Posted - 2014-05-19 : 09:40:11
|
To anyone interested:Apparently the ERP-system doesn't insert all fields at once so by changing the trigger to update instead of insert khtans code work perfectly.Best regardsPer Erik Midtrød |
 |
|
|
|
|