|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Escape Code for Stored ProcHi guys n gals, Im on hunt for an escape code or command for my TSQL
stored proc.. If Something = SomethingElse <Exit the Stored Proc> I feel a little dumb asking this but I Could not find any thing relating to termination aborting Exiting Ending etc... Regards Michael RETURN
-- Show quoteArnie Rowland, Ph.D. Westwood Consulting, Inc Most good judgment comes from experience. Most experience comes from bad judgment. - Anonymous "MichaelT" <Michael.Thomlin***@gmail.com> wrote in message news:1156531921.262255.289100@i3g2000cwc.googlegroups.com... > Hi guys n gals, Im on hunt for an escape code or command for my TSQL > stored proc.. > > If Something = SomethingElse > <Exit the Stored Proc> > > I feel a little dumb asking this but I Could not find any thing > relating to > > termination > aborting > Exiting > Ending > etc... > > Regards > Michael > I believe RETURN is what your looking for:
Exits unconditionally from a query or procedure. RETURN is immediate and complete and can be used at any point to exit from a procedure, batch, or statement block. Statements that follow RETURN are not executed Syntax RETURN [ integer_expression ] Arguments integer_expression Is the integer value that is returned. Stored procedures can return an integer value to a calling procedure or an application. Return Types Optionally returns int. Note: Unless documented otherwise, all system stored procedures return a value of 0. This indicates success and a nonzero value indicates failure. Show quote "MichaelT" wrote: > Hi guys n gals, Im on hunt for an escape code or command for my TSQL > stored proc.. > > If Something = SomethingElse > <Exit the Stored Proc> > > I feel a little dumb asking this but I Could not find any thing > relating to > > termination > aborting > Exiting > Ending > etc... > > Regards > Michael > RETURN;
Show quote "MichaelT" <Michael.Thomlin***@gmail.com> wrote in message news:1156531921.262255.289100@i3g2000cwc.googlegroups.com... > Hi guys n gals, Im on hunt for an escape code or command for my TSQL > stored proc.. > > If Something = SomethingElse > <Exit the Stored Proc> > > I feel a little dumb asking this but I Could not find any thing > relating to > > termination > aborting > Exiting > Ending > etc... > > Regards > Michael > Hi,
Your question implied a how to code for abnormal termination of procedures (?) RETURN will force exit from the procedure, but this may not be suitable for all situations e.g. SQL 2000 error-handling e.g. IF @@ERROR <> 0 , maybe running some audit trail code might be useful One construction thate can be used is:- ..... <body of procedure> SELECT @intError = @@ERROR IF @intError <> 0 GOTO procedureError ...... <more of the procedure> -- Procedure success GOTO endProcedure -- Must have this otherwise code in 'procedure error' is run produreError:- -- do stuff in respone to error endProcedure:- -- do other stuff regardless of what happens RETURN SQL 2005 of course replaces the above with BEGIN TRY ... END TRY BEGIN CATCH .... END CATCH The above constructions will ensure a single point of exit from procedures, and allow you to consistently handle how a procedure exits, and sets any relevant values (e.g. record failure or success in an audit trail table or whatever ..) Hope the above helps. Craig Show quote "MichaelT" wrote: > Hi guys n gals, Im on hunt for an escape code or command for my TSQL > stored proc.. > > If Something = SomethingElse > <Exit the Stored Proc> > > I feel a little dumb asking this but I Could not find any thing > relating to > > termination > aborting > Exiting > Ending > etc... > > Regards > Michael > > |
|||||||||||||||||||||||