ASE 11.9; SProcs; testing @@error; When to test it?? -
12-04-2003
, 02:04 PM
Sybase documentation for Strored Procs indicates that global variable
@@error should be checked as follows...
"Every Transact-SQL statement, including print statements and if tests,
resets @@error, so the status check must immediately follow the batch whose
success is in question."
So what we've done is test after EVERY line in our SProcs...
.....
select @todaydate = getdate()
if @@error <> 0 goto error_out
select @num_rows = COUNT(*) from can_2_job where c2j_c_key = @cankey
if @@error <> 0 goto error_out
open canjobs_spf1ce
if @@error <> 0 goto closeit_error_out
fetch canjobs_spf1ce into @thiscan, @thisjob
if @@error <> 0 goto closeit_error_out
.....
close canjobs_spf1ce
if @@error <> 0 goto error_out
deallocate cursor canjobs_spf1ce
if @@error <> 0 goto error_out
Needless to say, our SProcs are chock-filled with these lines, which I'm
guessing are not really useful.
Can anyone provide any general guidance as to when @@error should be checked
(and when it is not necessary)? The code as we've written it can't be what
the documentation intended we do.
Many Thanks |