Link to home
Start Free TrialLog in
Avatar of adamtrask
adamtrask

asked on

Storing the value of the function @@Error

Hi,


I am trying to see if I can store the values produced by function @@Error in a variable and, subsequently, print the value of the variable...

I understand that @@Error function automatically resets itself to 0 when it comes across a new line of code that is being evaluated, which means only the value of the last error is displayed but not the errors that comes before that.....  

In the example below the value of the variable @myVariable is printed as 0, but that's because no errors were found and because the function was only used once. Could you give me an example where the code produces more than one error and the value of each @@Error is printed

Declare @myVariable int
insert into Employee
Values
(62, 'Peter','Pan',GETDATE(),65,3,'Active','2002-08-12 00:00:00.0000000 -8:00','-8:00')
select @myVariable = @@Error
Print 'The value of Error is ' +  convert(varchar,@myVariable)

Thank you
ASKER CERTIFIED SOLUTION
Avatar of Brendt Hess
Brendt Hess
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of adamtrask
adamtrask

ASKER

Thanks bhess1...
This will come handy at some point...
Thanks