Mr.Sahand (7/22/2015)
Try this, should work for you.CREATE TRIGGER a_insert ON a
FOR INSERT
AS
BEGIN
Set XACT_Abort oFF
begin try
DECLARE @a AS VARCHAR(40)
SET @a = 'count of transaction' + CONVERT(VARCHAR(10), @@TRANCOUNT)
PRINT @a
end try
begin catch
rollback tran
end catch
END
GO
A rollback inside a trigger is almost always a poor decision. If your calling code is expecting there to be a transaction it will likely fail because the transaction was rolled back inside the trigger. It is usually best to let an exception bubble up from inside a trigger and let the calling code handle the exception.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/