In a "religious" discussion about formatting of Microsoft T-SQL code, I questioned whether or not the GOTO statement was still available in T-SQL syntax. In 13 years of using T-SQL I have never had occasion to use it, and indeed didn't know if it existed. After a brief search of the documentation and to my consternation it does indeed exist!
My question is this:
Is there at least one case where GOTO statements would yield a solution that performs better than one in which other higher order programming constructs are used?
My question is NOT:
I almost never use GOTO
and can easily live without it.
The one case where I would consider using it is when I have complicated code that does lots of error checking. I might want to take some action when an error returns, and GOTO
allows me to define a single block of code for the error checking.
You can solve this problem in multiple ways, but GOTO
is a reasonable option that guarantees that errors are processed consistently and the code is not cluttered with a lot of if @Error = 0 . . .
statements.