0

I am faced with the following error -

Number (213) Severity (16) State (5) Server (ASED052) Insert error: column name or number of supplied values does not match table definition.

and I am trying to catch it with -

IF @@ERROR != 0
BEGIN
-- Do stuff
END

However, I have found out that this error does not set the global @@ERROR variable. As such is the case, does anyone know of another method to catch this error?

Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
czchlong
  • 2,434
  • 10
  • 51
  • 65

3 Answers3

0

Have you tried using the following functions?

ERROR_LINE()
ERROR_MESSAGE()
ERROR_NUMBER()
ERROR_PROCEDURE()
ERROR_SEVERITY()
ERROR_STATE()

Or you could use a try/catch block :

BEGIN TRY
...
END TRY
BEGIN CATCH
...
END CATCH
Dominic Goulet
  • 7,983
  • 7
  • 28
  • 56
0

Try this solution:

I. Create a procedure with the code that generates error.

create procedure Proc1
as
begin
  insert into tab(Fake_Column) 
  values ('aaa')
end

II. Run procedure Proc1 and catch error:

exec Proc1

IF @@error <> 0
begin
    print 'ERROR!'    
end
Robert
  • 25,425
  • 8
  • 67
  • 81
0

Apparently there is no way to catch the specified error using the global @@ERROR variable.

czchlong
  • 2,434
  • 10
  • 51
  • 65