RETURN clause, clarification

  • 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"...

    🙁


    "If I had been drinking out of that toilet, I might have been killed." -Ace Ventura

  • 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


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • THANK YOU!


    "If I had been drinking out of that toilet, I might have been killed." -Ace Ventura

  • You bet... thanks for the feedback.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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