Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RETURN statement performance?

Status
Not open for further replies.

spDavCom

Programmer
Feb 16, 2003
13
US

QUESTION:

I've heard that using the RETURN statement can boost performance because SQL Server will not create a recordset.

Where does the return statement go in my stored proc?

NOTE:
I'm using asp.net to call my stored procs.

Any input or syntax is much appreciated in advance. Thank you.
 
The RETURN statement should be the last statement in the stored procedure or at whatever point you would like to RETURN from the procedure. I use it in error handling to bail out of a procedure early and on inserts to RETURN the identity created by the insert. Something like this:

Code:
CREATE PROC usp_DoIt
  @NameToInsert varchar(20) NULL
AS BEGIN
  SET NOCOUNT ON

  IF @NameToInsert IS NULL BEGIN
     RaisError('Invalid name',16,1)
     RETURN -1    --There is an error so bail out
  END

  INSERT Names (TheName) VALUES (@NameToInsert)

  RETURN @@Identity    --ID of the inserted row
END
--Angel [rainbow]
-----------------------------------
Every time I lose my mind, I wonder
if it's really worth finding.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top