In this blog, I have explained how to make optional parameters by specifying default values in SQL Server Stored Procedures.
To demonstrate the above concept I will use the following table:
- CREATE TABLE Mas_Employee
- (
- Id int IDENTITY PRIMARY KEY,
- Name nvarchar(50),
- Gender nvarchar(50),
- Salary int,
- DeptId int
- )
Here is Mas_Employee table, now use the following scripts:
- Insert into Mas_Employee ( Name, Gender, Salary, DeptId )
- Select 'Jaipal', 'Male', 18200, 1 Union All
- Select 'Jayanth', 'Male', 12200, 2 Union All
- Select 'Sreeshanth', 'Male', 12999, 2 Union All
- Select 'Sujit', 'Male', 8000, 3 Union All
- Select 'Tejaswini', 'Female',16800, 1 Union All
- Select 'Akhil', 'Male', 10000, 5 Union All
- Select 'Jayalalitha','Female',8000, 4 Union All
- Select 'Deepak', 'Male', 12999, 2 Union All
- Select 'Arun', 'Male', 15000, 1

Janakiram JanPosted May 20, 2022, 5:42 AM
If we specify default values for the parameters then they are optional parameters. Thanks for the information.
Anijim James-MauricePosted Mar 24, 2021, 11:28 PM
Nice use of ISNULL function. The only con is that you have to specify NULL if you want to skip the first parameter. If that parameter could be skipped completely, the function would be perfect. Thanks all the same ??
Jaipal ReddyPosted Sep 7, 2016, 6:01 AM
Thank you Subash
SubashPosted Aug 20, 2016, 4:38 AM
Nice one