SQL Tutorial - Stored Procedures OUTPUT Parameters

Описание к видео SQL Tutorial - Stored Procedures OUTPUT Parameters

Another video brought to you by BeardedDev, bringing you tutorials on Business Intelligence, SQL Programming and Data Analysis.

You can now support me on patreon -   / beardeddev  

If you are new to working with Stored Procedures, check out this video here:    • SQL TUTORIAL - How to create a Stored...   on how to create a stored procedure.

In this video we take a lot at stored procedure output parameters within SQL Server.

Output Parameters enable us to return a value to the caller.

In this tutorial we create a basic stored procedure that has two input parameters and one output parameter. We pass in values for Employee First Name and Last Name and return the Employee position.

We then show that if we just execute the stored procedure without assigning the output variable then an error is shown.

We then talk about how we can assign the output parameter value that is returned to a variable that will enable further use within SQL Server.

SQL in this video:
CREATE PROCEDURE spReturnEmployeePosition
@FirstName VARCHAR(50)
, @LastName VARCHAR(50)
, @Position VARCHAR(50) OUTPUT
AS

BEGIN

SELECT
@Position = EmployeePosition
FROM dbo.Employees
WHERE EmployeeFirstName = @FirstName
AND EmployeeLastName = @LastName

END

DECLARE @Pos VARCHAR(50)
EXEC dbo.spReturnEmployeePosition @FirstName = 'Tony', @LastName = 'Smith', @Position = @Pos OUTPUT
PRINT @Pos

As always I hope you enjoy the video and remember to subscribe to BeardedDev.

If you would like to see any video tutorials in future on the channel let me know in the comments.

Комментарии

Информация по комментариям в разработке