Error Checking & Output Params

  • I just have a couple questions about how everyone else handles these two issues:

    Q1:

    Do you check for @@error after all your select, update, etc statements? i.e.

    select field1, field2

    from table1

    where field1 = n

    if (@@error <> 0) return -1

    Q2: If you are just selecting one record from a table that has say 15 fields would you define the output as parameters or a 1 record recordset? When does the number of fields outweigh the benefit of not using a recordset?

    thx, joe

  • I use @@error when I think I need to, not after every statement. If it's always going to be one record I use output parameters unless Im returning other recordsets from the same proc. Not sure where the cutoff is, I just try to use output params whenever I can.

    Andy

  • 1.For error checking I create a local variables @ErrNum and @ErrDesc and setting like:

    set @ErrNum = @@ERROR

    set @@ErrDesc = "Invalid Client Code"

    if @ErrNum <> 0 GOTO myerror

    In error handler you can return not only status ( "Failure") but also reason and do some other stuff, like roll back transaction, etc

    I put this error check after any insert/update statement, for input validation and in any other places that required special attention.

    2. If I have one record with a lot of fields - I would return the record and then use fields from it in the application

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

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