On a table in MS SQL Server I need to run a CLR Stored Procedure on new rows if those rows meet certain criteria. I thought that would be more or less straightforward:
if ((SELECT Cabinet FROM INSERTED) = 1 OR (SELECT Cabinet FROM INSERTED) = 3) AND (SELECT Result_02 FROM INSERTED) = 'N'
BEGIN
DECLARE @id int
SET @id = (SELECT ID FROM INSERTED)
exec PrintLabel
@id,
N'LP 2844 LGE'
END;
However, this recently started throwing errors about a subquery returning multiple rows. I learned that INSERT triggers run once for each statement, not necessarily on individual rows. So, that IF statement can be working on multiple rows, and thus the error.
My question is: how can I iterate over each new row if the rows are added in a batch (in this case via a MERGE statement).
Calling a stored procedure for N rows still requires a cursor.