Solution 5 : Implementing Optional Parameters in T-SQL Stored Procedures
You have a stored procedure GetCustomers with two parameters: LastName, FirstName. The stored procedure returns all the records matching the values of the parameters. You want the parameters be optional, which means skipping the parameter if you do not pass a value.
T-SQL does not provide optional parameters, but you can implement one.
1. You have original stored procedure

2. Add =null at your parameter declaration of the stored procedure
![]()
3. Add IS NULL at your WHERE clause

4. Now you have optional parameters in the stored procedure

5. Call the stored procedure from your data access layer C# code (FirstName is optional)
