Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2004
    Posts
    107

    Unanswered: Understanding @@ERROR ....

    My question is in what situations @@ERROR will be set...

    I like to do some logic when some error is occured in a particular statement....

    the doc. says the @@ERROR value will be set if an error occurs in a statement, and the control will move to the next statement without exiting(???) the procedure and @@ERROR value can be used in that statement.

    but when i execute the below procedure, the execution is terminated ( when the error occurs) without moving to the next statement. please help me to understand the SQL Server's @@ERROR and the situations when it will be set....

    -----------------------------------------------------------------------
    CREATE PROCEDURE VALUE_ERROR_TEST
    AS
    BEGIN
    DECLARE @adv_error INT
    DECLARE @errno INT
    DECLARE @var int
    SELECT @var = '101 a'
    SELECT @errno = @@ERROR
    print @errno
    END
    go
    -----------------------------------------------------------------------
    procedure get successfully compiled. when executed it says,

    Server: Msg 245, Level 16, State 1, Procedure VALUE_ERROR_TEST, Line 10
    Syntax error converting the varchar value '101 a' to a column of data type int.


    Jake

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    If you want to make sure a value is numeric, make the parameter varchar, then use ISNUMERIC to verify before moving on...
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

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