Hi there,
I'm pretty sure you are allowed to use @@error in triggers. (Anyone: am I wrong on that?) So I'm wondering if there's any other issue we could be seeing here.
One thing you are probably aware of is that @@error only applies to the immediately preceding t-sql statement.
So for example:
INSERT statement.....with an error in it.
Print 'Hello'
Select @@error
Here, @@error would be zero, because the immediately preceding statement (print) worked.
Here's a more common example:
INSERT statement.....with an error in it.
set @myrowcount = @@rowcount
Select @@error
Again, @@error will not show an error, because the prior statement (set @myrowcount) worked.
Do you think this might bear on what you are seeing?
If so, to get around this, we usually capture @@error right away to a local variable, before any other statement can change its value:
declare @myerror
set @myerror = 0
INSERT statement.....with an error in it.
set @myerror = @@error
.....
Now you can use @myerror wherever you want.
Hope this helps a bit. But I feel sure you can use @@error in a trigger.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.