Execute a stored procedure in Microsoft SQL Server

Syntax of Execute stored procedure in MSSQL Server

Execute the Stored Procedure with exec command:

Taking an example of stored procedure as follows:

Syntax of Procedure: ALTER PROCEDURE [dbo].[uspGetEmployeeManagers] @BusinessEntityID [int]

Pass parameter direct with comma seperated or use can give the parameter name with @ and specify its value.

--Example of different ways:
EXEC [dbo].[uspGetEmployeeManagers] 3455


USE [AdventureWorks2017]
DECLARE              @return_value int
EXEC      @return_value = [dbo].[uspGetEmployeeManagers] 3455
SELECT  'Return Value' = @return_value


EXEC  [dbo].[uspGetManagerEmployees] @BusinessEntityID = 3455


DECLARE              @return_value int
EXEC      @return_value = [dbo].[uspGetWhereUsedProductID]                                @StartProductID = NULL,
@CheckDate = NULL
SELECT  'Return Value' = @return_value

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.