Hello all --
Hopefully a simple one for you.
I have several SPROCs that create dynamic SQL statements inside themselves and then execute those statements through the use of:
sp_executesql
Here's the thing, though. They use division in their execution, and from time to time, the denominator in the equation turns out to be a zero. Currently, I keep the number of operations to 1 inside the SPROC and then if it returns any error whatsoever, I assume it was a divide by zero, and then return an appropriate answer to my user in the ASP page where it's used.
However, I would like to handle these errors inside the SPROC so that I could do multiple operations with one call to the SPROC and then have the SPROC return the appropriate values depending on whether or not a divide by zero was encountered on any of the three operations I wish to complete.
So far, I know I can check for an error like this:
IF @@error != 0
/*something went wrong -- presumably a divide by zero, so do something
That's all fine and dandy, but I've been unable to figure out how to clear that error inside the SPROC so that I can go on and do another operation, and then use the same methodology to find out if an error occured there.
In ASP, it's err.clear -- to reset the error value to 0, but how would I do this in the SPROC?
Or, if you have any words of wisdom on how I might improve this train of thought, that would also be welcome.
Thanks for your input.
Paul Prewett
Hopefully a simple one for you.
I have several SPROCs that create dynamic SQL statements inside themselves and then execute those statements through the use of:
sp_executesql
Here's the thing, though. They use division in their execution, and from time to time, the denominator in the equation turns out to be a zero. Currently, I keep the number of operations to 1 inside the SPROC and then if it returns any error whatsoever, I assume it was a divide by zero, and then return an appropriate answer to my user in the ASP page where it's used.
However, I would like to handle these errors inside the SPROC so that I could do multiple operations with one call to the SPROC and then have the SPROC return the appropriate values depending on whether or not a divide by zero was encountered on any of the three operations I wish to complete.
So far, I know I can check for an error like this:
IF @@error != 0
/*something went wrong -- presumably a divide by zero, so do something
That's all fine and dandy, but I've been unable to figure out how to clear that error inside the SPROC so that I can go on and do another operation, and then use the same methodology to find out if an error occured there.
In ASP, it's err.clear -- to reset the error value to 0, but how would I do this in the SPROC?
Or, if you have any words of wisdom on how I might improve this train of thought, that would also be welcome.
Thanks for your input.

Paul Prewett

