Search notes:
SQL Server function: xact_state
It returns 0 if no transaction is active and 1 if one is active.
If there is an active transaction which caused an error, it returns -1.
set nocount on;
create table tq84_xact_state(col int);
select 'xact_state = ' + str(xact_state(), 2);
--
-- xact_state = 0
--
begin transaction;
select 'xact_state = ' + str(xact_state(), 2);
--
-- xact_state = 1
--
insert into tq84_xact_state values (1);
commit;
select 'xact_state = ' + str(xact_state(), 2);
--
-- xact_state = 0
--
drop table tq84_xact_state;
go