Thanks, and you are quite welcome :). And that reminds me:
I was going to mention to Sergey that the question, in its current form, is actually a little ambiguous since "0" is a possible answer, under a certain condition. If the session level setting of XACT_ABORT is ON, then @@TRANCOUNT will immediately go to 0 (including a rollback of the transaction itself). This question assumes that XACT_ABORT is OFF (which is typically the case), but it would be best to explicitly state that in the question, just to remove any possible confusion. You can see the effect below. It is the same code as in the question, but I set XACT_ABORT ON at the top, which then causes an error in the CATCH block since the only thing you can do in a CATCH block when XACT_ABORT is ON and an error happens is execute ROLLBACK. I also added the "GO" so that the error doesn't prevent the SELECT @@TRANCOUNT from showing that it is indeed 0. And of course the conditional ROLLBACK at the bottom to make testing easier when you change XACT_ABORT to OFF which then leaves the @@TRANCOUNT at 2.
SET XACT_ABORT ON;
IF OBJECT_ID('tempdb..#tmpTable') IS NOT NULL
DROP TABLE #tmpTable
CREATE TABLE #tmpTable(ID INT NOT NULL)
SAVE TRANSACTION T1
INSERT INTO #tmpTable(ID)
ROLLBACK TRANSACTION T1
GO -- added to allow SELECT to work when XACT_ABORT is ON and causes error in CATCH block
SELECT @@TRANCOUNT AS 'TRANCOUNT'
IF (@@TRANCOUNT > 0)
PRINT 'Rolling back transaction...';
Take care, Solomon...