Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

RETURN clause, clarification Expand / Collapse
Author
Message
Posted Friday, January 14, 2011 2:30 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, August 20, 2014 5:06 PM
Points: 154, Visits: 584
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
Post #1048219
Posted Friday, January 14, 2011 2:45 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 4:24 PM
Points: 36,995, Visits: 31,522
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1048225
Posted Friday, January 14, 2011 2:48 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, August 20, 2014 5:06 PM
Points: 154, Visits: 584
THANK YOU!


"If I had been drinking out of that toilet, I might have been killed." -Ace Ventura
Post #1048228
Posted Friday, January 14, 2011 4:51 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 4:24 PM
Points: 36,995, Visits: 31,522
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1048268
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse