I have a trigger that is causing an error when multiple items are inserted to the db (I use cold fusion, each query is in a seperate <cfquery> tag.)
When one insert query is run, it runs just fine, but when multiple are passed, I get an error
I'm assuming that the red line in the code section above is what's causing the error... How do I avoid this? How do I process after each and every insert query rather than in bulk?
Code:
CREATE TRIGGER InsertBalance ON [dbo].[Credits]
FOR INSERT, UPDATE
AS
DECLARE @CreditUserID INT
[red]SELECT @CreditUserID = (SELECT CreditUserID FROM Inserted)[/red]
update users
set balance = Abs(ISNULL((select sum(creditamount)
from credits
where creditUserID = @CreditUserID),0))
where userid = @CreditUserID
When one insert query is run, it runs just fine, but when multiple are passed, I get an error
Error Executing Database Query. [Macromedia][SQLServer JDBC Driver][SQLServer]Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The error occurred on line 41.
I'm assuming that the red line in the code section above is what's causing the error... How do I avoid this? How do I process after each and every insert query rather than in bulk?