Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2004
    Posts
    7

    Unanswered: @@ERROR not working

    I wrote a store procedure like the following

    create procedure....as
    begin
    declare @e int
    select @e = 0
    begin trans
    insert.....
    if @@ERROR<>0
    begin
    @e = @@ERROR
    print "...."
    end
    if @@ERROR<>0
    begin
    @e = @@ERROR
    print "...."
    end
    if @e=0 then
    commit transaction
    else
    rollback transaction
    return 0


    it is not working....when any error (especially wrong table name)...it is raising an error and no commit or rollback getting executed in the second statement....no other setting is made apart from the above code.

  2. #2
    Join Date
    Nov 2002
    Location
    Switzerland
    Posts
    524
    1) lowercase
    2) attribute a value using select

    Code:
    create procedure....as
    begin
       declare @e int
       select @e = 0
       begin trans
       insert.....
       if @@error<>0
          begin
          select @e = @@ERROR
          print "...."
         end
    ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •