@@LINENUMBER ???

  • I want to have something in my procs that when an error happens, gives the line # of the error.

    .

    .

    .

    if @InstID is null

    begin

    rollback transaction

    select 'error on line number: ' + @@LINENUMBER

    end

    .

    .

    .

    Anyone?

  • I've never seen such a variable in Sql server. The only thing comparable to that would be the line number provided with sql server's error messages. But I don't think you can access that info. If you really need to have err handling you'll have to code it yourself.

  • I am not aware of any function built in to SQL Server that will provide what you are asking for. 

    However, a line number typically is only useful to the developer - not to the end user.  For developer purposes, you might want to take a look at the SQL debugger built into Query Analyzer.  If you are working in a .Net project world, then you can do debugging all the way from your app down through the stack and into the stored procs.

    Hope this helps

    Wayne

  • You will find the error handling in T-SQL to be, well, primitive. There is no function that returns the line number for an error. One reason may be that databases are set-related instead of row-related. Unless you are constructing cursors knowing which line failed is not useful since we are "all or nothing" types.

    You should also be aware that our @@Error label resets itself for every statement (one of those little gotchas in T-SQL) so your

    " rollback transaction

    select 'error on line number: ' + @@LINENUMBER "

    would return a 0 since the rollback transaction statement was successful.

    Quand on parle du loup, on en voit la queue

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

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