I ran into an interesting problem while writing an update trigger in SQL Server 2008. I right-clicked on the triggers folder for a table and selected "New trigger". Now the new trigger template adds "SET NOCOUNT ON;" at the beginning. Normally it is a good practice so that the rows affected message doesn't interfere with select statement results.
...
SET NOCOUNT ON;
IF(@@ROWCOUNT) = 1
BEGIN
...
The problem I encountered is that I was checking the @@ROWCOUNT variable to see if only one row had been affected and by having the NOCOUNT statement before my if statement the @@ROWCOUNT was being reset to 0.
The solution was simple, I just moved the NOCOUNT statement before my UPDATE statement in the trigger.
1892bffa-51ea-4459-a5ab-f58a7aab59ef|0|.0
BlogEngine.NET
sql server triggers