@@error not working

Posted on 2011-04-20
Last Modified: 2012-05-11
   The @@error does not return error code when doing single insert. The query anayzer editor does not seems to have any special settings. The sqlserver is 2000.

Thanks a lot

Question by:amitabh04
    LVL 9

    Expert Comment

    Can you please share a sample code and what exactly the error is...
    LVL 21

    Expert Comment

    by:Alpesh Patel
    When you use the @@error, please take it in other local variable. Because after a single use of @@error will be flushed automatically.

    Set @Errorval = @@error

    Author Comment

      The code is like the folowing and still it does not work. I am trying to catch constraint error.

    insert into b..tab1 select x, y from tab2

    set @err = @@error

    if ( @err > 0 ) then


    LVL 75

    Accepted Solution

    If that was in fact your code, then there was no error.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Introduction In my previous article ( I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
    Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
    Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
    Viewers will learn how the fundamental information of how to create a table.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now