Error trapping in TSQL

  • I'm stumped. We have the following table :-

    CREATE TABLE [dbo].[NotifierGroup] (

    [NotifierID] [smallint] NOT NULL ,

    [Operator] [varchar] (50) COLLATE Latin1_General_BIN NOT NULL ,

    [Email] [varchar] (60) COLLATE Latin1_General_BIN NOT NULL

    )

    when we run the following code against it understandably it produces an error which we can trap

    DECLARE @ErrorSave INT

    SET @ErrorSave = 0

    insert into dbo.NotifierGroup values ( 99999999, 'xxx', 'zzz' )

    SET @ErrorSave = @@ERROR

    print @ErrorSave

    However when we run the following against the database that does not have the Employees table in it

    DECLARE @ErrorSave INT

    SET @ErrorSave = 0

    SELECT FirstName, LastName, Title

    FROM Employees

    SET @ErrorSave = @@ERROR

    print @ErrorSave

    we only get

    Server: Msg 208, Level 16, State 1, Line 1

    not the expected

    208

    Any thoughts, work rounds, resolutions greatly appreciated

     

    Stuart

    -------------------------------Posting Data Etiquette - Jeff Moden [/url]Smart way to ask a question
    There are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. ― Carl Sagan
    I would never join a club that would allow me as a member - Groucho Marx

  • See. if this helps:

    http://www.sommarskog.se/error-handling-II.html

    http://www.sommarskog.se/error-handling-I.html

     

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply