Execute SQL Server procedure with parameters

How to execute a stored procedure with parameters? Depending on the implementation of the SQL Server code, call the procedure with all parameters or only one. First you have to set the value NULL in the procedure code.

This is because we create the parameters in a mandatory or non-mandatory way. For optional parameters, we can assign a default value in the create statement of the SQL procedure. So optional parameters are not stopping from executing the procedure and getting a potential feedback in SSMS.

How to execute a stored procedure using parameters in SQL Server?

First of all, create the procedure to call, or make sure the target im already in the database. If not, execute the code of the uspGetCustomer stored procedure created from this article. In this stored procedure, the unique parameter as input, Customer ID, is a mandatory one.

Here is a simple example on how to execute a SQL Server stored procedure with one or more parameters as input. Indeed, to pass the input information to the SQL code, execute this code and adapt this syntax to your specific business case:

EXEC dbo.uspGetCustomer
@CustomerID = 1 ;
EXEC dbo.uspGetCustomer
@CustomerID = 2 ;