Get return values SQL Server


show more Getting return values provides you with in-depth training on Business. Taught by Martin Guidry as part of the SQL Server: Triggers, Stored Procedures, and Functions show less
please wait ...

Getting return values

I mentioned earlier to you a recommendation that as a best practice; every stored procedure return a value indicating success or failure. Typically, we return a 0 for failure and the 1 for success. We haven't yet implemented that. So let's go ahead and work on it. I'll change this code that creates a stored procedure into a code that alters a stored procedure. The last allow will be RETURN 1 for success. We also need to define some failure condition. As a hypothetical, we're going to say that if the first name is too short, let's say extremely short, less than two characters, we'll define that as a failure condition.

Check for the if len(@FirstName). If it's less than 2 characters, that is now defined as a failure condition. So we'll need to RETURN a 0 to indicate this stored procedure was unsuccessful. And as soon as it hits that line of RETURN 0, it will not execute the bottom. It will not do the insert. Command(s) completed successfully. That's good news...

Getting return values
Video duration: 2m 53s 1h 52m Advanced

Viewers:

Getting return values provides you with in-depth training on Business. Taught by Martin Guidry as part of the SQL Server: Triggers, Stored Procedures, and Functions

Subjects:
Business Developer IT
Software:
SQL Server
Author:
please wait ...