The return keyword exits from a batch or procedure unconditionally. It can be used at any point in a batch or a procedure. When used in stored procedures, return can accept an optional argument to return a status to the caller. Statements after return are not executed.

The syntax is:

return [int_expression] 

This stored procedure uses return as well as if...else and begin...end:

create procedure findrules @nm varchar(30) = null as 
if @nm is null 
  print "You must give a user name" 
   select,, sysobjects.uid 
   from sysobjects, master..syslogins 
   where = @nm 
   and sysobjects.uid = master..syslogins.suid 
   and sysobjects.type = "R" 

If no user name is given as a parameter when findrules is called, the return keyword causes the procedure to exit after a message has been sent to the user’s screen. If a user name is given, the names of the rules owned by the user are retrieved from the appropriate system tables.

return is similar to the break keyword used inside while loops.

Related concepts
Stored Procedures