@@TRANCOUNT (Transact-SQL)
SQL Server 2005
Returns the number of active transactions for the current connection.
Transact-SQL Syntax Conventions
This example uses @@TRANCOUNT to test for open transactions that should be committed.
USE AdventureWorks; GO BEGIN TRANSACTION; GO UPDATE Person.Contact SET LastName = UPPER(LastName) WHERE LastName = 'Wood'; GO IF @@TRANCOUNT > 0 BEGIN PRINT N'A transaction needs to be rolled back.'; ROLLBACK TRANSACTION; END