autoexcrement (1/14/2011)
Sorry, this might be my dumbest post yet. But I can't seem to find a simple explanation.I'm unclear on exactly what "RETURN" does. BoL says it "[immediately] exits unconditionally from a query or procedure."
But then in the context of a UDF, you have to have a RETURN clause, which is followed by stuff that you want to be returned.
So which is it? Does it exit immediately, or does it return stuff that follows it?
And then, to make matters worse for stupid people, there's also "RETURNS"...
🙁
RETURN does both. It exits the current proc and returns to the calling proc or the "system" that called it. If a value follows the RETURN, it also returns that value.
It is not usual to consider it to be an "abort" though because if a sproc is called from another sproc, the RETURN doesn't stop the outer sproc from continuing. It's more like a "RETURN" from GOSUB in BASIC.
--Jeff Moden
Change is inevitable... Change for the better is not.