Search notes:

SQL Server function: xact_state

xact_state() can be used to determine if a session (?) has an active transaction.
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
Github repository about-MSSQL, path: /t-sql/functions/xact_state.sql

See also

T-SQL functions

Index